Jump to content

how to structure database to handle user's friends


boonamera

Recommended Posts

What would be the best way to structure a database so that users can add friends.

Right now i have a simple user table which includes
userid
username
password
emai

thanks

edit:
ok more info:
let's say the following user
1
boonamera

wants to add as a friend
2
booya

how would you record this relationship?
I'm asking what field would you put in the friends table if that's how you suggest doing it.

What you are describing is a "many to many" relationship, i.e. each member can have a number of other members as friends, each of whom can also have many friends, etc. So you need a new table to break this up into a "one to many" relationship.

So I would suggest a new table which records:

userid
friendid

so that userid corresponds to the userid in your user table, and friendid also corresponds to the userid in the user table, of one of his friends. That way you could add the same userid many times, each with a different friendid, that way each member can have as many different friends as they like and you have not wasted memory with fields for those members who do not have friends.

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.