Jump to content

Need Some Ideas..


Rustage

Recommended Posts

Couldnt think where to post this, but I suppose you could class it as php help.My problem is, im making a community website for gamers and I want to allow the members to add friends to their profiles, sort of like you would on facebook, myspace etc. But I can't think of a simple way to store peoples friends, I could have fields in the mysql such as "friend1" "friend2" etc. but i think that will be a waste of time really as some people might have 1,000 friends or even 10,000.Just wondering if anyone has any other ideas? Im not the best at php and mysql as im pretty much learning it as I go but thought id ask you guys if you have any ideas.Thanks very much, Rustage

Link to comment
Share on other sites

Would there be any (dis)advantages to having a table called friends, where col1 would be the userID of the user who sent the request, and col2 would be the userID of the receiver of the request? I am thinking about doing this, but I am not sure...

Link to comment
Share on other sites

It's not that bad, if each user ID is a 32-bit number then you need 8 bytes of storage to store one relationship. So it would take 8KB to indicate that Bob has 1000 friends. The main benefit is that it's a lot easier to search through that table if you're looking up relationships than it is to search through a bunch of CSV strings. Assume you have a user with ID 100, for example. You could just find all records that contain "100" somewhere in the string, but you're going to find "1100", "1000", etc. So in order to find all fields that have user 100 as a friend you need to look for these conditions:field contains only "100" and nothing elsefield starts with "100,"field ends with ",100"field contains ",100,"That query is going to take a lot more time than it will to look up an index on the relationship table.That's not even mentioning what you need to do if a user decides they want to remove one of their 1000 friends.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...