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
https://forums.phpfreaks.com/topic/58365-php-mysql-join/
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
https://forums.phpfreaks.com/topic/58365-php-mysql-join/#findComment-289443
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.