Php profile page

mcfelpe

Baseband Member
Messages
28
Good day everyone, I have a project and i need help on what approach should i do to my database, the project goes like this, It is a website in which each user will create their own profile. What should i do to my database so that the user can add another user member of the website, just like in friendster... wherein in my profile page, i can see my details, and at the right side, i can see my added friends...

Any suggestion will be highly appreciated... thank you....

by the way, i'm using html/flash/php/mysql
 
You should have a User table, with a user ID and all the user details, then perhaps column with a comma separated list of friends user ID's, then use PHP's explode() function to create an array of friends user IDs. You could then have a foreach loop go through the array, and grab info on the friend from the User table.
Code:
foreach($friendIDs as $friendID)
{
    $friendInfoResult = mysql_query("
    SELECT * FROM 
   `Users` 
    WHERE 
    `ID` = '" . $friendID . "'
    ");
    $friendInfo = mysql_fetch_assoc($friendInfoResult);
    // Then loop get all the other fields from friendInfo[0]["thefield"]
}
Note: There's probably a far more elegant solution in SQL itself, so good luck.
 
Yes i think its a good idea, but my concern is how many characters does the friendsID field allow? what if a user have so many friends, so the friendsID field would be like jason,mark,phillip,etc,etc,etc,etc,etc and so on...
 
Yes i think its a good idea, but my concern is how many characters does the friendsID field allow? what if a user have so many friends, so the friendsID field would be like jason,mark,phillip,etc,etc,etc,etc,etc and so on...

You have a very valid point, perhaps you could have a separate table named Friends, and have a schema containing UserID and FriendUserID, then adding a row for each friend a user has. You could retrieve all the user's friends with something like this:
Code:
SELECT * FROM `Friends` WHERE `UserID` == $TheUsersID
 
Back
Top Bottom