0

Hello to Everyone,
I m involving in social networking website in php.Can anybody help me for building add friend system in php?

3
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by cereal
1

So, you have a database. Every user must have an ID number. Then, you have one page, "people" page, and on this page are all people. And there are links next to every person name, like <a href="target.php">Add this person as friend</a>. As href you can use persons id, like this: href="addfriend.php?id=(personid)". And then, when somebody click on this link, the person ID will be saved in MYSQL table. So, people will have, in mysql table, something like this: data..., "friends: 1,2,3,4,62,549,16465,852212123", and when you want to read "friend", you have to use explode:

function getdata($id){
         //mysql connect....
         return $data; //name, nickname...
}
$friends="(their ids)"
$friends=explode(",",$friends);
echo "List of your friends:<br>";
foreach($friends as $friend){
         echo "".getdata($friend)."<br>";
}

PS. maybe better not to use ID, use code for every user, like this: 14fgd4ggh78h, you can make this code with this script:

$possible_characters="qwertzuiopasdfghjklxcyvbn0123456789"; //etc.
$code="";
for($i=1;$i<=20;$i++){
        $number=mt_rand(0,(strlen($possible_characters)-1));
        $code.=$possible_characters[$number];
}

But one better way is to create a file with friend's ID code. (eg. everyone has folder "friends" and in this folder there are files like 1dhdS45fAf5d6, sh4Ezhsg4hT, etc.)

0

@ivan3510
I think it's better to store friend's id on separate rows, it's easier to maintain, count and so on:

user_id | friend_id
-------------------
    1   |    23
    1   |    90
    2   |    37

:)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.