i have faced in a problem. Can you please write this query in cakephp format
Table
id from_id to_id is_active message
--- ------- ----- --------- -------
1 1 8 1 Hello
2 8 1 1 Yes
3 1 8 1 How are you?
4 1 8 1 Are you with me?
Code :
<?php
$qry = mysql_query("SELECT * FROM messages WHERE (from_id='8' OR to_id='1') AND (from_id='1' OR to_id='8') AND id_active='1'"));
$res = mysql_fetch_array($qry);
?>
Edit
I have written but getting null value
my code:
$condition = array('OR'=>array('Message.from_id'=>1,'Message.to_id'=>8),'OR'=>array('Message.from_id'=>8,'Message.to_id'=>1),'Message.is_active'=>1);
$message=$this->Message->find("all",array('conditions'=>$condition));
pr($message);
Output:
array
(
)
messagesand what you expect to see as output.to_idoffrom_idof 1, so your sample reduces down tofrom_id=8 AND to_id=8sqlfiddle.com/#!2/faa1b0/2