php - How to batch update multiple records using CodeIgniter query builder?
问题描述
I have looked at the other answers on this topic and I feel that I am following the documentation, but nonetheless I am not able to update. Below is the code in my model:
$query = $this->db->get();
$data = array();
foreach ($query->result_array() as $l_xAnswer) {
if ($l_xAnswer['status'] == '1' && $l_xAnswer['client_id'] == DB_CLIENT_ID) {
$data[] = [
'id' => $l_xAnswer['id'],
'status' => 2
];
}
}
return $this->db->update_batch('quiz_answers', $data, 'id');
The $data object at this point looks as follows (var_dump):
array(12) {
[0]=>
array(2) {
["id"]=>
string(5) "20223"
["status"]=>
int(2)
}
[1]=>
array(2) {
["id"]=>
string(5) "19165"
["status"]=>
int(2)
}
[2]=>
array(2) {
["id"]=>
string(5) "19129"
["status"]=>
int(2)
}
}
The selected records are not updating. At this point, I feel like I must be missing something obvious. Thank you for looking at this.
解决方案
推荐阅读
- mysql - 如何在第一次插入和第二次更新
- javascript - $.fn.dataTable.ext.feature.push() 未被调用
- reactjs - Reactstrap Modal 的内容对 jest mount 不可见
- rxjs - 有什么方法可以找出哪些流触发了 rxjs 中的合并运算符?
- javascript - 快速会话返回“未定义”,即使我声明了会话
- java - 如何将listview 放在horizontalscrollview 中,以便列表可以水平滚动?
- python-3.x - 是否可以在 Python 中基于控制台菜单的 UI 中应用多线程?如何?
- nested - 将数据从子模块传递到父模块Angular
- charts - Azure Devops 中管道的自定义指标图表
- javascript - Webpack 4 如何要求源作为单独的块并按需加载它们