supermerc Posted May 13, 2007 Share Posted May 13, 2007 Hey, I've made a friend system for my site where you can add other users as your friends, but I want to make it so you can select your top 5 friends that will be displayed in their profile. My table is set up like this. Where added is the id of the person being added, userid is the id of the person that is adding someone, state is the state where 0 is not accepted yet and 1 is accepted. Then I have the page displaying the friends: <?php session_start(); require("config.php"); require("functions.php"); $all_requests = mysql_query("SELECT * FROM friends WHERE ((userid='$_SESSION[s_id]')||(added='$_SESSION[s_id]')) AND state=1") or die(mysql_error()); if(mysql_num_rows($all_requests) > 0){ while($friends = mysql_fetch_assoc($all_requests)){ if($friends[userid]==$_SESSION[s_id]) $id[]=$friends[added]; else $id[]=$friends[userid]; } }else{ echo "You do not have any friend requests."; } foreach($id as $k=>$v){ $query=mysql_query("SELECT * FROM users WHERE `id`='$v' LIMIT 1") or die(mysql_error()); $row=mysql_fetch_assoc($query); echo '<img src="'.$row[Profilepic].'" width="50" height="50">'; } ?> But I dont know how to make it so you can set your top 5 allies, if someone can help me it would be GREATLY appreciated!. Quote Link to comment https://forums.phpfreaks.com/topic/51242-friend-system/ Share on other sites More sharing options...
Dragen Posted May 13, 2007 Share Posted May 13, 2007 I'm not sure how I'd do it.. maybe have a seperate table for it set up as: userid | friend1 | friend2 | friend3 | friend4 | friend5 1|67|52|31|12|3 where userid is the current users id and friends1 friends2 etc are their top 5 in order from 1 to 5. You'd just need to set up the mysql queries to checnge/view them Quote Link to comment https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-252424 Share on other sites More sharing options...
supermerc Posted May 13, 2007 Author Share Posted May 13, 2007 oh okay, Does anyone know how to make it so that lets say that you can drag the picture of your friend in order of top 5? Like you have the list of all your allies, and the first 5 spots are automaticly the top 5, then you an like drag other friends in those spots to replace them. Quote Link to comment https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-252434 Share on other sites More sharing options...
marf Posted May 14, 2007 Share Posted May 14, 2007 That would be using AJAX. I'm pretty sure some of the AJAX libraries, like scriptalicious, or moo...something, or prototype have drag and drop stuff in there, just a matter of figuring out how to use it. Quote Link to comment https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-252458 Share on other sites More sharing options...
supermerc Posted May 14, 2007 Author Share Posted May 14, 2007 Is there any other way? Quote Link to comment https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-252619 Share on other sites More sharing options...
neel_basu Posted May 14, 2007 Share Posted May 14, 2007 Change your SQL to this select .......... order by `id` ASC limit 5 Quote Link to comment https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-252634 Share on other sites More sharing options...
Dragen Posted May 14, 2007 Share Posted May 14, 2007 nah.. I think Ajax would be your best bet for that. I'm presuming you want something similar to on myspace where you can move your friends around? The other way would be a simple form where you can set your top friends EDIT: neel_basy, that's just make the friends with the lowest id the top five friends. There id should set how friendly they are with the user. Quote Link to comment https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-252662 Share on other sites More sharing options...
supermerc Posted May 17, 2007 Author Share Posted May 17, 2007 I have seen it done with php before on the site outwar.com I dont know how to do it thought Quote Link to comment https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-255803 Share on other sites More sharing options...
cmgmyr Posted May 17, 2007 Share Posted May 17, 2007 add a 'sort' column into your table, this is where you can add the correct sort number. Then when you query it you would do something like "...ORDER BY sort ASC LIMIT 5" For AJAX sorting: http://www.gregphoto.net/index.php/2007/01/16/scriptaculous-sortables-with-ajax-callback/ http://www.cyberdummy.co.uk/2005/07/13/multi-list-drag-and-drop/ hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-255811 Share on other sites More sharing options...
seb hughes Posted May 17, 2007 Share Posted May 17, 2007 Why nto have a friends table with, USER ID, FRIEND ID, STATE, and then use relations to get the USER ID etc Quote Link to comment https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-255815 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.