php - update_batch 中的多个 where / 键
问题描述
有人可以帮我吗,我想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'] ));
}
推荐阅读
- python-3.x - 检查目标字符串是否包含列表中的任何项目并获取索引的方法?| Python3
- sql-server - 如何在 SQL Server 中使用子查询而不是视图
- sass - 选择器的自动修复顺序
- scala - 使用 IntelliJ CE 调试 Spark 时无法命中断点
- typescript - 如何在不使用强制转换或为每个字段创建变量的情况下构建对象?
- python - 如何从尖括号列表中创建元组,后跟不带括号的单词
- node.js - 将我的 nodejs/expressjs 应用程序部署到 AWS lambda 后出现 bcrypt 错误
- python - 如何在 Python 中使用 Arcade 制作的现有窗口上制作更新计时器?
- python - 是否可以使用返回类型字典创建任意泛型类型提示?
- node.js - Discord.js - 删除所有包含角色的用户的命令