mikethecoder Posted December 8, 2006 Share Posted December 8, 2006 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 - Slave1 - 5 - 431 - 5 - 54So 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! Link to comment https://forums.phpfreaks.com/topic/29892-friend-list-please-give-advice-on-best-solution/ Share on other sites More sharing options...
liam1412 Posted December 8, 2006 Share Posted December 8, 2006 I wanted something similar but the solution was less than perfect. Any better ideasI 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 Link to comment https://forums.phpfreaks.com/topic/29892-friend-list-please-give-advice-on-best-solution/#findComment-137371 Share on other sites More sharing options...
liam1412 Posted December 8, 2006 Share Posted December 8, 2006 Sorry forgot to mention. Once the user has 20 friends it relys on them deleting one firs. I could not figure a way for them to select one to replace. Advise on this would be nice.Thanks Link to comment https://forums.phpfreaks.com/topic/29892-friend-list-please-give-advice-on-best-solution/#findComment-137373 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.