Tiered WHERE clause in CodeIgniter

I want to delete some data like this request which is in the core of PHP

WHERE user_id=$id AND sender_id=$send_id OR user_id=$send_id AND sender_id=$id

So, I tried it in CodeIgniter using Active Record, like this:

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

But this gives me the wrong result. What am I doing wrong?

+5
source share
2 answers
$this->db->where(array('user_id' => $id, 'sender_id' => $send_id));
$this->db->or_where(array('user_id' => $send_id, 'sender_id' => $id));

You want to pass an associative array to each of them, where it will use ANDbetween each element of the array in the request, and use ->or_where()will use ORin the request. Further information is available in the documentation .

+9
source

try it

    $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);
+2
source

All Articles