gpt4 book ai didi

php - codeigniter 使用多个 where 子句更新多行

转载 作者:行者123 更新时间:2023-11-29 01:15:54 24 4
gpt4 key购买 nike

当我尝试这段代码时:

$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);
}

它给我错误:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UPDATE community_members SET status = 'joined' WHERE community_id = '18' A' at line 4

this answer使用 CASE 的直接查询,但我不知道如何将其转换为 Codeigniter 的查询生成器..

最佳答案

试试这个例子;

你可以像这样直接使用数组 $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');

关于php - codeigniter 使用多个 where 子句更新多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41162094/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com