使用 explode & where in (codeigniter) 进行多次更新
multiple update using explode & where in (codeigniter)
各位早安,
我想使用 explode 函数和 where in for code igniter 更新多行,但问题是,所有行都已更新。
这是我的控制器:
$ids = explode(',', $this->post('id'));
$this->chatmod->update(array('id'=>$ids),$data);
我的模型:
public function update($ids=null,$data=null)
{
$this->db->where_in($ids);
$this->db->update($this->table, $data);
return true;
}
where_in
查询应提供目标列,例如:
$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;
}
要使用列 ID 进行更新,您需要在 where_in
函数中传递列名称,例如 $this->db->where_in("id",$idarray);
对于你的代码试试下面的代码:
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;
}
各位早安,
我想使用 explode 函数和 where in for code igniter 更新多行,但问题是,所有行都已更新。
这是我的控制器:
$ids = explode(',', $this->post('id'));
$this->chatmod->update(array('id'=>$ids),$data);
我的模型:
public function update($ids=null,$data=null)
{
$this->db->where_in($ids);
$this->db->update($this->table, $data);
return true;
}
where_in
查询应提供目标列,例如:
$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;
}
要使用列 ID 进行更新,您需要在 where_in
函数中传递列名称,例如 $this->db->where_in("id",$idarray);
对于你的代码试试下面的代码:
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;
}