Updating multiple rows from ids array

╄→尐↘猪︶ㄣ 提交于 2021-02-08 07:50:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!