[英]codeigniter update multiple rows with multiple where clause
when I try this code: 当我尝试这段代码时:
$query = '';
foreach ($data as $row)
{
$where = array(
'community_id' => $row->id,
'user_id' => $this->session->user_id,
'status' => 'invited_to_join',
);
$update = array(
'status' => 'joined',
);
$query .= $this->db->set($update)->where($where)->get_compiled_update('community_members').'; ';
}
if ($query)
{
return $this->db->query($query);
}
it gives me the error: 它给了我错误:
You have an error in your SQL syntax; 您的SQL语法有错误; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UPDATE
community_members
SETstatus
= 'joined' WHEREcommunity_id
= '18' A' at line 4 查看与您的MariaDB服务器版本对应的手册,以便在'UPDATEcommunity_members
'附近使用正确的语法SETstatus
='加入'WHEREcommunity_id
='18'A'在第4行
this answer uses straightforward query with CASE but I don't know how to convert that into Codeigniter's Query Builder.. 这个答案使用CASE直接查询,但我不知道如何将其转换为Codeigniter的查询生成器..
Try this Example; 试试这个例子;
You can direct use array $data['id']
like this and no need loop use here as my opine 您可以像这样直接使用数组$data['id']
,这里不需要使用循环作为我的操作
$this->db->set('status','joined');
$this->db->where('community_id',$data['id']);
$this->db->where('user_id',$this->session->user_id);
$this->db->where('status','invited_to_join');
$this->db->update('community_members');
You can also use where
clause this way: 您也可以这样使用where
子句:
$where = "'community_id'=".$data['id']." AND user_id=".$this->session-user_id." AND status='invited_to_join'";
$this->db->set('status','joined');
$this->db->where($where);
$this->db->update('community_members');
Thank You!!! 谢谢!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.