boonamera Posted July 20, 2006 Share Posted July 20, 2006 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 includesuserid usernamepasswordemaithanksedit:ok more info:let's say the following user1boonamerawants to add as a friend2booyahow 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. Quote Link to comment Share on other sites More sharing options...
Kurt Posted July 20, 2006 Share Posted July 20, 2006 Can you post more info? I hardly know what you mean ??? Quote Link to comment Share on other sites More sharing options...
king arthur Posted July 21, 2006 Share Posted July 21, 2006 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:useridfriendidso 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted July 21, 2006 Share Posted July 21, 2006 That's definitely the right approach... such a lookup is the best solution. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.