如何更新Codeigniter中的多条记录


public function asset_rep()
{
$astid = $this->input->post("astid");
//print_r($astid);die;
$astrep_id = $this->input->post("astrep_id");
$this->asset_model->update_asset_rep($astid,$astrep_id);
redirect("asset/index");
}
public function update_asset_rep($astid,$astrep_id)
{
$astrep = implode(',', $astid);
echo $astrep;
$this->db->where('id',$astrep);
$this->db->update('pm1asset',array('owner' =>$astrep_id));
echo $this->db->last_query(); 
}

在上面的代码片段中,第一个函数在控制器中声明,第二个函数在模型中声明。我想更新$astrep中具有id的多行的所有者。有人能帮我吗?

不要内爆$astid,而是确保它是数组并在中使用where

$this->db->where_in('id', $astrep);

您可以使用查询生成器类中的where In((或whereIn((方法。

请参阅https://codeigniter4.github.io/userguide/database/query_builder.html#looking-针对特定数据

最新更新