[英]Multi-Conditional WHERE Clause In CodeIgniter
我想刪除一些像核心PHP中的查詢這樣的數據
WHERE user_id=$id AND sender_id=$send_id OR user_id=$send_id AND sender_id=$id
所以我在CodeIgniter中嘗試使用Active Record,如下所示:
$this->db->where('user_id ', $id);
$this->db->or_where('user_id ', $send_id);
$this->db->where('sender_id ', $send_id);
$this->db->or_where('sender_id ', $id);
但它給了我錯誤的結果。 我究竟做錯了什么?
$this->db->where(array('user_id' => $id, 'sender_id' => $send_id));
$this->db->or_where(array('user_id' => $send_id, 'sender_id' => $id));
您希望將關聯數組傳遞給每個數組,它將在查詢中的數組中的每個元素之間使用AND
,並且使用->or_where()
將在查詢中使用OR
。 文檔中提供了更多信息。
試試這個
$this->db->where('user_id ', $id);
$this->db->where('sender_id ', $send_id);
$this->db->or_where('sender_id ', $id);
$this->db->where('user_id ', $send_id);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.