Boo-urns Posted February 5, 2007 Share Posted February 5, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/37105-solved-how-to-create-a-group/ Share on other sites More sharing options...
JasonLewis Posted February 5, 2007 Share Posted February 5, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/37105-solved-how-to-create-a-group/#findComment-177231 Share on other sites More sharing options...
Boo-urns Posted February 5, 2007 Author Share Posted February 5, 2007 Yea yea that's clear its how I'm doing the users pet information. Just wasn't sure if that was the way to go or not! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/37105-solved-how-to-create-a-group/#findComment-177237 Share on other sites More sharing options...
JasonLewis Posted February 5, 2007 Share Posted February 5, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/37105-solved-how-to-create-a-group/#findComment-177240 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.