Jump to content

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.

 

databaselx9.jpg

 

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!.

Link to comment
https://forums.phpfreaks.com/topic/51242-friend-system/
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

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

Link to comment
https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-252424
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
https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-252434
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
https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-252662
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:

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

Link to comment
https://forums.phpfreaks.com/topic/51242-friend-system/#findComment-255811
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.

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.