Jump to content

Recommended Posts

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.