这是我要来的
SELECT * FROM (`lkt_messages`) WHERE `sender_id` = '1' AND `receiver_id` = '2' OR `sender_id` = '2' OR `receiver_id` = '1' ORDER BY `added_on` DESC
我想要这样
SELECT * FROM (`lkt_messages`) WHERE `sender_id` = '1' AND `receiver_id` = '2' OR `sender_id` = '2' AND `receiver_id` = '1' ORDER BY `added_on` DESC
我在下面写下了这个问题。
$cls=MESSAGES_TBL;
$id= $this->session->userdata('user_id');
$condition_query=array('sender_id'=>$replymsg_id,'receiver_id'=>$id);
$condition_query1=array('sender_id'=>$id,'receiver_id'=>$replymsg_id);
$data=$cls::where($condition_query)->or_where($condition_query1);
$result=$data->order_by('added_on', 'DESC')->all();
return $result;
答案 0 :(得分:1)
以下更改应该有效:
$condition_query = "(sender_id = $replymsg_id and receiver_id = $id)";
$condition_query1 = "(sender_id = $id and receiver_id = $replymsg_id)";
$data = $cls::where($condition_query)->or_where($condition_query1);
答案 1 :(得分:0)
试试这个SQL查询: -
SELECT *
FROM (`lkt_messages`)
WHERE (`sender_id` = '1' AND `receiver_id` = '2')
OR (`sender_id = '2' AND `receiver_id` = '1')
ORDER BY `added_on` DESC