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.

Link to comment
Share on other sites

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