EchoFool Posted February 1, 2008 Share Posted February 1, 2008 Hey guys, I have a query which is causing problems as the "group by" is not working. Not sure how to fix the problem though. This is what i got: $Get = mysql_query("SELECT * FROM msgs WHERE Sender='$ID' OR Receiver='$ID' GROUP BY Sender,Receiver ORDER BY Time") Or die(mysql_error()); What is happening though is im getting two rows the reason why is because of this: In the table theres 2 rows like this: Sender | Receiver 2 99 99 2 This is why it comes out twice.. how do i merge it so it will only represent that as one not both? Because I am trying to get all users that $ID has spoke to "uniquely" so it should only show one row in the above case because $ID has spoke to ID 2 it doesn't need to tell me twice... hope you can help Link to comment https://forums.phpfreaks.com/topic/88905-solved-query-problems/ Share on other sites More sharing options...
cooldude832 Posted February 1, 2008 Share Posted February 1, 2008 what exactly is the goal of this query to retrieve a message? If so it should have a message ID to query from and not this sender/receive combo If you want all messages between two people simply say get all mesages were person A is the sender and Person B is the sender and then where person B was recieve of or person A Link to comment https://forums.phpfreaks.com/topic/88905-solved-query-problems/#findComment-455408 Share on other sites More sharing options...
EchoFool Posted February 1, 2008 Author Share Posted February 1, 2008 No sorry i should have explained better. I am trying to get the ID of the other person that $ID has contacted. For example: ID = 4 So say the table has: Sender | Receiver 4 99 3 4 99 4 3 2 1 4 4 45 The result from my query should show.... The users ID 4 has received or sent a message from/to are: 99 3 1 45 Link to comment https://forums.phpfreaks.com/topic/88905-solved-query-problems/#findComment-455634 Share on other sites More sharing options...
sasa Posted February 1, 2008 Share Posted February 1, 2008 try SELECT DISTINCT(IF(`Sender`='4',`Receiver`,`Sender`)) AS contacts FROM `msgs` WHERE `Sender`='4' or `Receiver`='4' Link to comment https://forums.phpfreaks.com/topic/88905-solved-query-problems/#findComment-455662 Share on other sites More sharing options...
EchoFool Posted February 1, 2008 Author Share Posted February 1, 2008 thanks its working Link to comment https://forums.phpfreaks.com/topic/88905-solved-query-problems/#findComment-455715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.