【问题标题】:How to update multiple records in Codeigniter如何更新 Codeigniter 中的多条记录
【发布时间】:2020-03-26 13:45:25
【问题描述】:
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(); 
}

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

【问题讨论】:

    标签: javascript php sql codeigniter


    【解决方案1】:

    不要内爆 $astid,而是确保它是一个 array 并使用 where_in

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

    【讨论】:

      【解决方案2】:

      您可以使用查询构建器类中的 whereIn()orWhereIn() 方法。

      参考https://codeigniter4.github.io/userguide/database/query_builder.html#looking-for-specific-data

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-21
        • 1970-01-01
        • 1970-01-01
        • 2017-09-14
        • 2019-02-18
        • 2016-05-01
        • 2013-05-02
        相关资源
        最近更新 更多