Jump to content

Friend list... please give advice on best solution!


mikethecoder

Recommended Posts

Okay so I have to create a decent sized virtual community online. Users will have profiles and can add other users on a "friend list". We all have seen this before. My question is what is the best way to program this in PHP? And also how should the database table for the friend list be structed? I was thinking have a table called friendlist and it would have a unique id for the primary key and then a field called "friendowner" and "slave" or something to that effect where both friends are foreign keys to the user table.

ID - Friendowner - Slave
1 - 5 - 43
1 - 5 - 54

So when the user whose id is 5 loads his profile it will show him having 2 friends whose id's are 43 and 54. But is this the best way to go? Lets say we have a site with 100k members and each member has 300 friends... that table would be huge. And the time it takes to search the table worries me. I suppose this is where caching could come in handy but still. Is there a more effective way? And could any type of indexing help?...I was thinking no since the fields will only consist of just numbers so its already sweet and to the point... just, a lot of data to sift through.

Please any help would be greatly appreciated!!! Thank you all!
I wanted something similar but the solution was less than perfect. Any better ideas

I created a table "Friend List with 21 fields and a user id coresponding to the userid in the "users" table.

This obviously limits the amount of friends they can have to 20 people.  When the user loads there profile a call to the friends list table echos out these into the required place on the profile.  If these are then set into the sessions on logon this will avoid overwriting the friends that are already there.

if(empty($_SESSION['freind 1']) {
(code to insert into table)
}else{
if(empty($_SESSION['freind 2']) {
(code to insert into table)
}

and so on.

This is is a very messy solution but it seems to work.  I am very beginner so I will probably get shot down in flames  :D.

I could do with a better solution also

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.