Jump to content

[SOLVED] How to create a group?


Boo-urns

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.

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.