Jump to content

PHP + MySQL JOIN


warclown

Recommended Posts

Hi.

 

Im making a website with userprofiles which includes a buddylist that I want to make.

The database contains two different tables (x_users and x_buddylist).

 

x_users table:

 

id , username

1  , warclown

2  , Leffa

3  , Testman

 

x_buddylist:

bid , ownerid , friendid

1  , 1          , 2

2  , 1          , 3

3  , 3          , 2

4  , 3          , 1

 

As you already probably understand: ownerid is the userid (from x_users)  aka the owner of the relationship, and friendid is the friend that has been added (also the userid from x_users).

 

The problem im facing is how to extract the information I want. Ive been told that MySQL JOIN is the way to do it, but all the guys Ive asked to help me understand the JOIN method has said the same thing "Read the manual, its hard to explain".

 

So I tried to learn the manual... many times, and i still dont understand how to extract the buddylist of f.ex user 1 (warclown in this case).

 

I want the buddylist to extract this info:

<a href='user.php?uid=(THE FRIENDID)'>(The Friend Name)</a>

Etc (The same thing over again downwards after how many friends the user has added.

 

Can anyone give me a spesific example on how to do this on my site (just write the examples after my tables and rows given above). I know that I will learn more by seeing exactly what I shouldve done combined with the theory on the mysql manual site.

 

Please help :)

 

Best regards,

Simen 'warclown'

Link to comment
Share on other sites

Actually I came that far by myself.

But my main problem was how to echo it.

 

How can I echo the users in the buddylist ? I need the PHP  code to retrieve the ones that is specified by the userid - and I need it to get the friend id's and automatically retrieve the username of that friendid so I can echo it out.

 

It sounds complex :o

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.