當我嘗試這種代碼:笨更新多行的where子句
$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
SETstatus
= 'joined' WHEREcommunity_id
= '18' A' at line 4
this answer使用簡單的查詢使用CASE,但我不知道如何將其轉換爲Codeigniter的查詢生成器。
謝謝!我知道它必須非常簡單..我想知道爲什麼我看不到第二個和第三個子句可以像這樣加入.. – dapidmini
當然,您可以使用加入where子句.... @ dapidmini –
$ where =「'community_id'=」。$ data ['id']。「AND user_id =」。$ this-> session-> user_id。「AND status ='invited_to_join'」; $ this-> db-> where($ where); –