php - batch update in codeigniter with simple array -


i want batch update in codeignter , pass array data, instead of running multiple queries.

array ( [439] => 0 [440] => 0 [441] => 0 [442] => 1 [443] => 0 ) 

the 439, 440, 441, 442, 443 id's , 0, 0, 0, 1, 0 values need put active column.

i can achieve running thru loop, want batch update.

foreach($this->input->post($field_name) $key => $value) {     $insert = array(         'id'        =>  $key,         'active'    =>  $value,     );      $this->db->where('id', $key)->update($table, array('active' => $value)); }    

build array foreach loop, use batch update.

edit: forgot second array() in opening array. may or may not needed.

$data = array(array());  foreach($this->input->post($field_name) $key => $value) {     $push = array(         'id'        =>  $key,         'active'    =>  $value,     ); array_push($data, $push); } $this->db->update_batch('mytable', $data, 'id'); 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -