sql - Codeigniter: Update multiple Rows in Codeigniter in one statement -


i having dictionary

array(    'id1' => 1 ,    'id2' => 2,    'status' => 'done'  )

while have 2 columns in table, id , status. want update 2 rows having ids 1, , 2, using 1 time ($this->db->update). possible or should have make custom query. want ($this->db->update(where id1 == 1 && id2 == 2)).

either

// status  $item = array( 'status' => $response['status'] );  // unset status unset($response['status']);  // assume except status rest values ids // array_values gives id $this->db->where_in('id', array_values($response));  // update table $this->db->update('table', $item ); 

or

you have modify array

    $data = array(        array(          'id' => 1 ,          'status' => 'done'        ),        array(          'id' => 2 ,          'status' => 'done'        )     ); 

and then

    $this->db->update_batch('table_name', $data, 'id'); 

like can modify

( comment : dear cant so, because getting response service. , not able edit response. )

[akshay@localhost tmp]$ cat test.php <?php $response = array(   'id1' => 1 ,   'id2' => 2,   'status' => 'done' );  $data = array();  $item = array( 'status' => $response['status'] ); unset($response['status']);  foreach($response $new){         $item['id'] = $new;         $data[] = $item;  } print_r($data);  // here update  // $this->db->update_batch('table_name', $data, 'id'); ?> 

output

[akshay@localhost tmp]$ php test.php array (     [0] => array         (             [status] => done             [id] => 1         )      [1] => array         (             [status] => done             [id] => 2         )  ) 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -