问题
I have an array like so:
Array ( [0] => 6599 [1] => 6600 )
This array, will be much larger in a live scenario.
I need to update my database table rows which have the entry_id
(s) in this array, updating just one column status
, with the value open
.
I had thought I could use update_batch
(https://www.codeigniter.com/userguide2/database/active_record.html#update, but I couldn't get it to work.
How can I achieve this?
回答1:
You can use where_in method
$ids = Array(12,34,55,677,123);
$this->db->where_in('id', $ids);
$this->db->update('table', array('status' => 'open'));
来源:https://stackoverflow.com/questions/31315607/updating-multiple-rows-from-ids-array