Jump to content


Photo

friends system ???


  • Please log in to reply
14 replies to this topic

#1 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 28 August 2006 - 04:21 PM

I'm trying to figure out how i would have a "friends" or "buddies" feature.. like myspace.. how would i go about inserting what data where.. idk how to start with this.
Link shortener with advanced, detailed statistics:

http://tyny.us/

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 28 August 2006 - 04:27 PM

You could have a table which links id's

just 2 fields

id
friendid

so when they log in you will have the id then just query this table to get the id's of their friends

Ray

#3 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 28 August 2006 - 04:27 PM

well you could have a seperate table say called 'friends'with the fields 'username' and 'friend' and then simply add a new row for the user each time they add a friend and then to show you simply do "select friend from friends where username = '$username'" and echo all the users back otherwise you could use a unique row for each user and have friends comma seperated in the database.

justa  few idea's

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#4 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 28 August 2006 - 04:33 PM

so i did something like this in phpMyAdmin. is this on the right track?

CREATE TABLE `friends` (
`username` VARCHAR( 31 ) NOT NULL ,
`friend` VARCHAR( 31 ) NOT NULL 
) TYPE = MYISAM ;

Link shortener with advanced, detailed statistics:

http://tyny.us/

#5 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 28 August 2006 - 04:36 PM

I think I get it .. well I do :-P but how would I add a row when they add a user as a friend??
Link shortener with advanced, detailed statistics:

http://tyny.us/

#6 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 28 August 2006 - 04:37 PM

well you could do it that way. Only problem there is if the person changes his or her name. If you connect then thru their unique id, they can change every thing in the row and it will still link correctly.

You can do it the way you have it you like. If you do it by unique id you just need to change the field to an interger maybe 11 long

Ray

#7 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 28 August 2006 - 04:42 PM

they cant change their username, so i wont run into that prob  :P
Link shortener with advanced, detailed statistics:

http://tyny.us/

#8 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 28 August 2006 - 04:44 PM

They may not be able to change their username, but numbers are far easier and faster to query than strings. Plus you do not have to worry about stupid character which may be interpreted by php and sql incorrectly.

Well first thing is how you want them to find the friend. you want a dropdown menu of everyone in the table?? probably not but is an option. You can add it by them browsing to other peoples profiles. This would be the best way. when a person browses to someone elses profile, that persons id will be available. Also the person doing the browsing should have logged in and their id can be held in a session so you could have a link to a page which adds the id's

<?
$id = $_SESSION['userid'];
$friend = $_POST['userid'];  //or $_GET whichever you prefer

$sql = "INSERT INTO friends SET
  userid = '".$id."',
  friend = '".$friend."'";

Hope that gets you on the right track, and hope I didn't mess you up with the session stuff

Ray

#9 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 28 August 2006 - 05:17 PM

i got it to work !! but .. now i have a prob. i want to add a send message button ... heres my code..

<hr width=35%><br><br>
<b>Add Friend:</b>
<form action="" method="post">
      <table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td bgcolor="#66CCCC"><font color="black">Username:</font></td></tr>
<tr><td bgcolor="#66CCCC">"><input type="input" name="friendUN"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="friendNew" value="-Add Friend-"></td></tr>
</table>
</form>
<b>YourFriends:</b>
<?php 
$query = mysql_query("SELECT * FROM friends WHERE `username` = '$_SESSION[username]'");
while ($array = mysql_fetch_array($query)){
echo "<br><center><b>" .$array['friend']. "</b></center>";
echo "<a href='sendMessage.php?friend='" .$array['friend']. "'><input type='submit' name='friend' value='-Send Message-'></a>";
 }
?>

this line:
echo "<a href='sendMessage.php?friend='" .$array['friend']. "'><input type='submit' name='friend' value='-Send Message-'></a>";

takes me to "sendMessage.php?friend="
why ...
Link shortener with advanced, detailed statistics:

http://tyny.us/

#10 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 28 August 2006 - 05:18 PM

I guess I didnt need to show the form code .. nothing is wrong with that
Link shortener with advanced, detailed statistics:

http://tyny.us/

#11 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 28 August 2006 - 05:20 PM

try


<hr width=35%><br><br>
<b>Add Friend:</b>
<form action="" method="post">
      <table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td bgcolor="#66CCCC"><font color="black">Username:</font></td></tr>
<tr><td bgcolor="#66CCCC">"><input type="input" name="friendUN"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="friendNew" value="-Add Friend-"></td></tr>
</table>
</form>
<b>YourFriends:</b>
<?php 
$query = mysql_query("SELECT * FROM friends WHERE `username` = '$_SESSION[username]'");
while ($array = mysql_fetch_array($query)){
$friend=$array['friend'];
echo "<br><center><b>" .$friend. "</b></center>";
echo "<a href='sendMessage.php?friend='" .$friend. "'><input type='submit' name='friend' value='-Send Message-'></a>";
 }
?>

www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#12 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 28 August 2006 - 05:22 PM

in the sendMesage.php?friend= ....

I want the textbox called "to", to be filled with the value of "friend"

heres the "to" code

<input type="text" name="to" value="<? echo $_GET[friend]; ?>"

and "to" is never filled with anything! help!!
Link shortener with advanced, detailed statistics:

http://tyny.us/

#13 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 28 August 2006 - 05:24 PM

That's because your using POST in your form change

<form action="" method="post">

to

<form action="" method="get">
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#14 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 28 August 2006 - 05:35 PM

well heres the code i have that echos all your friends and a send message button for each user:

<?php
$query = mysql_query("SELECT * FROM friends WHERE `username` = '$_SESSION[username]'");
while ($array = mysql_fetch_array($query)){
$friend=$array['friend'];
echo "<br><center><b>" .$friend. "</b></center>";
echo "<form action='' method='get'><a href='sendMessage.php?friend='" .$friend. "'><input type='submit' name='friend' value='-Send Message-'></a></form>";

 }
?>

the button STILL takes me to "sendMessage.php?friend="
Link shortener with advanced, detailed statistics:

http://tyny.us/

#15 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 28 August 2006 - 05:41 PM

because you have nothing with the value of the get in your submitting the form change

echo "<form action='' method='get'><a href='sendMessage.php?friend='" .$friend. "'><input type='submit' name='friend' value='-Send Message-'></a></form>";


to

echo "<a href='sendMessage.php?friend='" .$friend. "'>Send Message</a>";

That will do the job :)
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users