I wish to create a buddies list during my video game. I don't know how to put it together or how to start. The add buddies and accept buddies part I'm able to handle, but I'm not sure how to put it together in mysql and php. A listing of customers (buddies) attached to each user or something like that?

In case your friendship relationship is shaped, you may either store each pair inside a separate record:

friend1 friend2
A       B
B       A
A       C
B       D
C       B
D       B

and query all B's buddies like this:

SELECT  friend2
FROM    friends
WHERE   friend1 = 'B'

or keep user using the least id within the first area which using the finest id within the second one:

friend1  friend2
A        B
A        C
B        D

and query B's buddies like this:

SELECT  friend1
FROM    friends
WHERE   friend2 = 'B'
SELECT  friend2
FROM    friends
WHERE   friend1 = 'B'

The very first choice is a bit more efficient in MySQL, which is your best option in case your friendship relationship isn't shaped (like on LiveJournal)

Check this out article:

A friendship is basically a mutual relationship between a couple. In database terms it is a many-to-many relationship between two customers.

What exactly you'll need is really a connecting table that holds references to 2 customers by ID.


Customers table

ID    Username
1     Bob
2     Jim
3     Alice

Buddies table

user1    user2
1        2
2        3

This could make Bob buddies Jim and Jim buddies with Alice.

Browse the solutions within this other publish here on stackoverflow...some simple but great explanations to achieving the thing you need.

Facebook database design?