codeigniter活动记录多更新 [英] Codeigniter Active Record multi-update

查看:114
本文介绍了codeigniter活动记录多更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用活动记录如何更新多行?

How can I update multiple rows using active record?

我的阵列

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

在我更新表,我需要的,其中子句(id_customer和id_section)中定义2个参数,但如果我用 update_batch ,我只能指定一个参数。 在,其中子句中如何设置几个参数?

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?

推荐答案

这样的事从的 code点火文档 - 参见更新批: -

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'); 

在你的情况的数据将被替换 $这个 - >。service_batch 和称号所需的列

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

这篇关于codeigniter活动记录多更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆