Jump to content

Archived

This topic is now archived and is closed to further replies.

pro_se

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

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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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...

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
user [b]A[/b] goes to user [b]B's[/b] profile. User [b]A[/b] clicks a link to add to buddy list. User [b]A[/b] now has user [b]B[/b] on his profile. User [b]B[/b] also has user [b]A[/b] on his profile.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
i know how to insert it i dont know how to display the thing... its two tables coming together...  users and friends...

Share this post


Link to post
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.

Share this post


Link to post
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...

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
also you may want to change the name of the second $result to avoid overwriting the first.

Share this post


Link to post
Share on other sites

×

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.