I have a table example
ID | answer1 | answer2 | question
1 | abc | ghi |
2 | def | klm |
I Wanna update column question by select ID This my code to get ID form table example
$query = $this->db->query('SELECT * FROM example');
$data=array();
foreach($query->result() AS $value){
$data[] = $value->id;
}
$implode = implode(',',$data);
//get from post
$question= $this->input->post('question');
foreach($question AS $q){
$data[]=array(
'id' => $implode,
'question' => $q
);
}
$this->db->update_batch('example',$data,'id');
//I use multiple add filed
<button class="add_field_button2">Add More Fields</button>
<input type="text" name="question[]" value="<?= $rowk->question;?>">
When add 2 question for update the table onlu one row is changed
My data array
Array ( [0] => Array ( [id] => 1,2 [question] => question1 ? ) ) Array ( [0] => Array ( [id] => 1,2 [question] => question1 ) [1] => Array ( [id] => 107,108 [question] => question2 ) )