这是我用来更新所有行的代码,我使用的是update_batch函数,但是它无法正常工作
SELECT LogDate,
LogTime AS InTime,
(
SELECT TOP 1 t1.LogTime
FROM yourTable AS t1
WHERE Mode = 0
) AS OutTime FROM yourTable WHERE Mode = 1
我的$ users var_dump看起来像这样
public function edit_project_involved($users)
{
foreach ($users as $v_user) {
$data=array('involved'=>1);
$v=$this->db->where('user_id',$v_user);
$query=$this->db->update_batch('tbl_users',$data,$v);
}
if($query)
{
return true;
}
}
我收到这样的错误
C:\wamp64\www\spectra\application\models\Project_model.php:536:
array (size=3)
0 => string '40' (length=2)
1 => string '42' (length=2)
2 => string '37' (length=2)
文件名:C:/wamp64/www/spectra/system/database/DB_query_builder.php
行号:2010
我的表格看起来像这样
One or more rows submitted for batch updating is missing the specified index.
var_dump($ data)看起来像这样
user_id username involved
1 admin 0
36 siraj 0
37 faizal 0
38 nesru 0
40 jaseer 0
42 maltu 0
43 shahul 0
44 samsheera 0
答案 0 :(得分:0)
您没有遵循文档https://www.codeigniter.com/user_guide/database/query_builder.html
中提到的规则试试这个(注意循环外的update_batch
以及数组的制作方式)
foreach ($users as $v_user) {
$data[] = array(
'user_id' => $v_user,
'involved'=> 1
);
}
$query = $this->db->update_batch('tbl_users',$data,'user_id');