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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -