mysql query problem
Sample data of my mysql.
id | id2 | sender | recipient | senderread | recipientread | Title
31 | 31 | A177 | B213, A256| yes | yes | Question123
32 | 31 | A256 | A177 | yes | no | Answer456
33 | 33 | A256 | A177 | yes | no | Question1337
34 | 31 | B213 | A177 | yes | yes | Answer456
35 | 31 | A177 | B213 | yes | no | R:Answer456
I am trying to get the output like below
Result 1 //listing the full conversation with user B213.
31 | 31 | A177 | B213, A256| yes | yes | Question123
34 | 31 | B213 | A177 | yes | yes | Answer456
35 | 31 | A177 | B213 | yes | no | R:Answer456
Result 2 //listing the full conversation that user A177 didnt read yet.
31 | 31 | A177 | B213, A256| yes | yes | Question123
32 | 31 | A256 | A177 | yes | no | Answer456
example.com/message.php?id=31
First step I am trying is trying to get the result if id or id2 is 31.
$query = mysql_query('SELECT * FROM pm where id="'.$id.'" or id2="'.$id.'");
Current user is A177, trying to pull the data if sender is A177 and recipientread = "no"...
$_SESSION['user'] = "A177";
$query = mysql_query('SELECT * FROM pm where id="'.$id.'" or id2="'.$id.'" and sender = "'.$_SESSION['user'].'" and recipientread = "no"');
And this is not working already...I am kinda lost now...can someone please give me a hand?
Thanks