有人能帮我吗?我想用带双键的update_batch
更新这个数量(no_trans&stock_id(?
$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'
)
);
我试试
$this->db->update_batch('table', $data, array('no_trans','stock_id'));
但不是工作
update_batch
命令使用单个where子句。(刚刚测试(
要归档您的目标,您必须使用foreach
和update
/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'] ));
}