【问题标题】:multiple update using explode & where in (codeigniter)使用explode & where in (codeigniter) 进行多次更新
【发布时间】:2018-09-18 12:23:49
【问题描述】:

早安,

我想使用explode函数更新多行以及代码点火器的位置,但问题是,所有行都更新了。

这是我的控制器:

$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;
    }

【问题讨论】:

  • $ids 是一个数组吗?

标签: arrays codeigniter explode where-in


【解决方案1】:

要使用列 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;
}

【讨论】:

    【解决方案2】:

    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;
        }
    

    【讨论】:

      猜你喜欢
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      • 2021-08-02
      • 2019-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多