简体   繁体   English

update_batch 中的多个 where / 键

[英]multi where / keys in update_batch

can someone help me, i want to update with this qty with update_batch with double keys (no_trans & stock_id)?有人可以帮我吗,我想用带有双键(no_trans 和 stock_id)的update_batch更新这个数量?

 $data = array(
       array(
          'no_trans' => '001' ,
          'stock_id' => 'aaa' ,
          'qty' => '100'
       ),
       array(
          'no_trans' => '001' ,
          'stock_id' => 'aab' ,
          'qty' => '200'
       ),
       array(
          'no_trans' => '002' ,
          'stock_id' => 'aaa' ,
          'qty' => '300'
       ),
       array(
          'no_trans' => '002' ,
          'stock_id' => 'aac' ,
          'qty' => '400'
       )
    );

i try with我尝试

$this->db->update_batch('table', $data, array('no_trans','stock_id'));

but is not work但不是工作

update_batch command works with a single where clause . update_batch命令与单个 where 子句一起使用 (Just tested) (刚测试过)

To archive your goal you have to use foreach with update / replace command要归档您的目标,您必须使用foreachupdate / replace命令

foreach ($data  as $key => $item) {
    $update = array(
        'qty' => $item['qty']
        );

    $this->db->where('no_trans', $item['no_trans']);
    $this->db->where('stock_id', $item['stock_id']);
    $this->db->update('table', $update);

    # or simple way /One Line

    $this->db->update('table', $update, array('no_trans' => $item['no_trans'], 'stock_id' => $item['stock_id'] ));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM