Jump to content

mysql query comparing columns


shortysbest

Recommended Posts

I have a table called "friends" and 4 columns called:  id......friend_1......friend_2.......date

 

I want to retrieve all of the friends of the user that is logged in, so if the table looks like:

 

friend_1.........friend_2

3.........................6

6.........................8

12.......................3

 

the result if the users id is 3 would be:

6

12

and if the users id was 6 it would be:

3

8

 

 

the query I have right now partially works, just note sure how to modify it to get the full result I want.

 

$get_friends = mysql_query("SELECT * FROM friends WHERE (friend_1='".$session."' OR friend_2='".$session."')");
while($friends = mysql_fetch_array($get_friends))
{
print $friends['friend_1'];
}

with the code above if you use the table I showed above and assumed that $session = 3, the result is:

3

12

 

but should be:

6

12

 

hopefully that's pretty straight forward, thanks in advanced.

Link to comment
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.