php - Adding an array to an existing array and saving with CodeIgniter -
i have following function:
function savecoa() { $labref = $this->uri->segment(3); $data = $this->input->post('compedia'); $data1 = $this->input->post('specification'); count($data) == count($data1); ($i = 0; $i < count($data); $i++) { $insert_data = array( 'labref' => $labref, //ndqa201303001 'compedia' => $data[$i], 'specification' => $data1[$i] ); $this->db->insert('coa_body', $insert_data); }
it saves well, have modified shown below:
$labref=$this->uri->segment(3); $test_id= $this->getrequestedtestids($labref); $data = $this->input->post('compedia'); $data1 = $this->input->post('specification'); count($data) == count($data1) && count($data)== count($test_id); ($i = 0; $i < count($data); $i++) { $insert_data = array( 'labref' => $labref, //ndqa201303001 - same rows 'test_id'=>$test_id[$i], //added array 'compedia' => $data[$i], 'specification' => $data1[$i] ); $this->db->insert('coa_body', $insert_data); }
the value of $test_id printed out print_r()
as:
array ( [0] => array ( [test_id] => 5 ) [1] => array ( [test_id] => 7 ) [2] => array ( [test_id] => 9 ) [3] => array ( [test_id] => 10 ) )
i have added array $test_id
, , returns:
error number: 1054 unknown column 'array' in 'field list' insert `coa_body` (`labref`, `test_id`, `compedia`, `specification`) values ('ndqa201303001', array, 'alphy', 'poxy') filename: c:\xampp\htdocs\nqcl\system\database\db_driver.php line number: 330
what missing?
looks $test_id[$i]
or $test_id[0]
array contains key test_id
you're giving mysql query array. instead this:
'test_id' => $test_id[$i]['test_id'], //added array
eg. print_r($test_id[0])
give you:
array ( [test_id] => 5 )
i hope it. have nice day.
Comments
Post a Comment