Jump to content

Recommended Posts

What would be the best way to create a 'friends' category on a site.  (similar to facebook, myspace with pictures also) Would it be better to enter every one in the database and link it to that particular user, or should i do something else? Just point me in the right direction! Thanks  :)

 

Corey

Link to comment
https://forums.phpfreaks.com/topic/37105-solved-how-to-create-a-group/
Share on other sites

make a new table in your mysql called friends with 3 fields. id, user_id and friend_id

the id field is going to be the auto_increment and the primary key.

 

then when they add a friend you just insert the id of the friend and the id of the person who is adding the friend then just grab the friend by select * from table where user_id is the persons id.

 

hope that is clear.

if you want to grab the information for the friend just do it as you normally would.

 

example:

$user_id = $_SESSION['id'];

$query = mysql_query("SELECT * FROM friends WHERE `user_id`='{$user_id}'");
while($r = mysql_fetch_array($query)){
$friend_info = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE `id`='{$r['friend_id']}'"));
echo "Friend Name: {$friend_info['username']}<br>Pet: {$friend_info['pet']}<br><br>";
}

 

and if your pet info was in a different table then you could just continue to select data.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.