更新编码器点火器中的多个记录


update multiple records in codeigniter

我正在做一个CodeIgniter项目,我必须更改记录的状态。实际上,我只需要更新那些 id 在 ids 刺痛中的记录。

目前,只有一条记录使用我的代码更新。我的模型函数是:

public function markUnRead() {
    $ids = 1,2,3,4,5,6;
    $update = array('status' => 0);
    $this->db->where_in('id', $ids);
    $this->db->update('tableName',$update);
    if ($this->db->affected_rows() > 0) {
        return true;
    } else {
        return false;
    }
}

请有人帮我。

where_in()方法的第二个参数应该是array

$this->db->where_in('id', array(1,2,3,4,5,6));

无论如何,如果$ids是像 "1,2,3,4,5,6" 这样的字符串,您可以通过以下方式使其工作:

$ids = explode(',', $ids);
$this->db->where_in('id', $ids);