multiple update using explode & where in (codeigniter)

给你一囗甜甜゛ 提交于 2020-01-06 07:10:18

问题


Morning guys,

I would like to update multiple row using explode function and where in for code igniter, but the problem is, all rows all updated.

here is my controller :

$ids = explode(',', $this->post('id'));
$this->chatmod->update(array('id'=>$ids),$data);

my model :

public function update($ids=null,$data=null)
    {
        $this->db->where_in($ids);
        $this->db->update($this->table, $data);
        return true;
    }

回答1:


For updating using column id you need to pass the column name in the where_in function like $this->db->where_in("id",$idarray);

For your code Try the below code:

public function update($ids=null,$data=null)
{
    $this->db->where_in('id',$ids);////Pass the column name of the database as first argument.
    $this->db->update($this->table, $data);
    return true;
}



回答2:


The where_in query should be supplied with target column, like :

$ids = explode(',', $this->post('id'));
$this->chatmod->update($ids,$data);

public function update($ids=null,$data=null)
    {
        $this->db->where_in('id', $ids);
        $this->db->update($this->table, $data);
        return true;
    }


来源:https://stackoverflow.com/questions/49727259/multiple-update-using-explode-where-in-codeigniter

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