CodeIgniter中的多条件WHERE子句 [英] Multi-Conditional WHERE Clause In CodeIgniter
本文介绍了CodeIgniter中的多条件WHERE子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要删除核心PHP中的某些数据,例如此查询。
I want to delete some data like this query that is in core PHP
WHERE user_id=$id AND sender_id=$send_id OR user_id=$send_id AND sender_id=$id
所以我在CodeIgniter中使用Active Record这个:
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 it gives me the wrong result. What am I doing wrong?
推荐答案
$this->db->where(array('user_id' => $id, 'sender_id' => $send_id));
$this->db->or_where(array('user_id' => $send_id, 'sender_id' => $id));
你想传递一个关联数组到每个数组,它将使用和将使用
OR
在查询中数组中的每个元素之间使用 - > code>。有关详情,请参阅文档。
You want to pass an associative array to each one, where it will use AND
between each element in array in query, and using the ->or_where()
will use an OR
in the query. More info is available in the documentation.
这篇关于CodeIgniter中的多条件WHERE子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文