Jump to content

Friend system


Recommended Posts

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:


$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];
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());
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!.

Link to comment
Share on other sites

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



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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:




hope this helps

Link to comment
Share on other sites

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.

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.