Jump to content

Need help with select query


waynew

Recommended Posts

I'm working on a social network at the moment that allows users to do a number of things. This includes adding each other as friends.

 

The problem is based around this friends system.

 

The table looks a little like this:

 

friendship_id

user_id_a

user_id_b

confirmed

 

When a user sends a friend request, his or her user id is inserted into user_id_a and the person who was sent the friend request has his or her id inserted into user_id_b. When user_b accepts, the column confirmed is updated and set to 1.

 

Now the problem is with selecting a persons friends. How do I select a users friends without selecting his or her data along with it? Because currently I have a query that goes along the lines of

 

Select friends.friendship_id, user.name FROM friends, user WHERE ((friendship.user_id_a = '$current_user') OR (friendship.user_id_b = '$current_user'))

 

That's a basic gist of how I'm going about doing it. Note that I have to select the name from the user table too. Otherwise I'll get everything dumped out. I have a query working at the moment, but it is far from optimal.

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.