duanqi6274 2013-08-01 14:25
浏览 47
已采纳

Codeigniter Active Record多次更新

How can I update multiple rows using active record?

My array

foreach($services as $service){

        $this->service_batch[]=array(
            'service_id'=>$service->service_id,
            'service_count'=>$service->service_count,
            'id_customer'=>$service->id_customer,
            'id_section'=>$service->id_section);
        }

When I update the table, I need define 2 parameters in the WHERE clause (id_customer AND id_section), but if I use update_batch, I can specify only one parameter. How can I set a few parameters in the WHERE clause?

  • 写回答

2条回答 默认 最新

  • dongmin4052 2013-08-01 14:44
    关注

    something like this from the Code Igniter Documentation - See Update Batch :-

     $data = array(
       array(
          'title' => 'My title' ,
          'name' => 'My Name 2' ,
          'date' => 'My date 2'
       ),
       array(
          'title' => 'Another title' ,
          'name' => 'Another Name 2' ,
          'date' => 'Another date 2'
       )
    );
    
    $this->db->where($this->db->where('id', $id);
    $this->db->update_batch('mytable', $data, 'title'); 
    

    in your case data will be replaced by $this->service_batch and title by your desired column.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用