Jump to content

*** solved *** friends system*** solved ***


pro_se

Recommended Posts

hey everyone!!! okay... i want to create a friend system similar to myspace... i was thinking i could create a sql table named friends with 2 columns one being 'friendid' and the other 'userid' and when they click add friend it inserts the information... i dont know what the query would be... oh and they also have avatars the url is saved in a table called users... any tutorials or someone that knows how to do this will be great...
Link to comment
Share on other sites

This could be a very big project or a very simple one, all depending what you really want to do. I would first look in to SQL query language if you are going to be using that as your backend. Once you get that down start with some simple INSERT INTO and SELECT FROM stuff and display results on a page. From there you will start to pick up things quickly.
Link to comment
Share on other sites

I know the owner of mypsace.com and trust me, that is a very big project if you want something planned like that.

You would need seperate tables, one for paying members, the other for music, arts, the list goes on.

You have to take into account blogs, private messaging, search's (sql 'SELECT * FROM dbname') then retreviing them and displaying.

Depends on what you are trying to do though, give me abit more information
Link to comment
Share on other sites

lol... i already have the whole site running on a local server but im just adding to it.... it is written in php, runs off of mysql.... i just want a user to be able to add a friend and once taht is done also have the friend to display the person that added him...
Link to comment
Share on other sites

You will have to create a page to select the friend or search for them. You would than also need to write a function or a script to actually add the friend's id to the database and also some code to actually show the user's friends.

If you can outline exactly what you want them to be able to do and how you want it to be done, we might be able to offer some better help.
Link to comment
Share on other sites

Okay...

So when a user is viewing another user's profile do you pass their own information with them? For instance does their user id follow them in a session or cookie or anything like that? If so how is that done and what name does the variable use?
Link to comment
Share on other sites

okay so then you would do something like this to display the user's friends on their profile.

[code]$sql="SELECT * FROM friends WHERE userid='{$_GET['id']}'";
$get_friends=mysql_query($sql);
while($friends=mysql_fetch_assoc($get_friends)){
     //echo friends, grab their info and print pictures, etc.
}[/code]

So if you were viewing the priofile of userid=99

The page would grab all the rows from the friends table that had a userid of 99. You could then display the info of every friend, each row being a different friend using somthing like this...

[code]echo $friends['name'];
echo $friends['email'];[/code]

Hope that helps some.
Link to comment
Share on other sites

[b]display[/b][code]<?php
$userid = $_GET['id'];
$result = mysql_query("SELECT * FROM friends WHERE userid='$userid'");
while($r=mysql_fetch_array($result))
{
  $friendid=$r["friendid"];
 
$result = mysql_query("SELECT * FROM users WHERE id='$friendid'");
while($r=mysql_fetch_array($result))
{
$avatar=$r["avatar"];
$uname=$r["uname"];
echo "<table width=15% height=102 border=0 align=left cellpadding=3 cellspacing=0>
  <tr>
    <td height=102 align=center valign=top><a href=user.php?id=$friendid><img src=$avatar width=90 height=90 border=0 /><br />
      $uname </a></td>
  </tr>
</table>";
}
}
?>[/code]

so i thought about it and this is what i came up with... and it works!!!! but it only displays one avatar... :( hEEELllPPPP... it must be somthing small...
Link to comment
Share on other sites

You don't need the second while loop.

You only select one friend at a time with $result, that is why it only prints one friend.

[code]<?php
$userid = $_GET['id'];
$result = mysql_query("SELECT * FROM friends WHERE userid='$userid'");
while($r=mysql_fetch_array($result))
{
   $friendid=$r["friendid"];
   
$result = mysql_query("SELECT * FROM users WHERE id='$friendid'");
$r=mysql_fetch_array($result);

$avatar=$r["avatar"];
$uname=$r["uname"];
echo "<table width=15% height=102 border=0 align=left cellpadding=3 cellspacing=0>
  <tr>
    <td height=102 align=center valign=top><a href=user.php?id=$friendid><img src=$avatar width=90 height=90 border=0 /><br />
      $uname </a></td>
  </tr>
</table>";

}
?>[/code]
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.

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.