Jump to content

friends system ???


techiefreak05

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

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

$sql = "INSERT INTO friends SET
  userid = '".$id."',
  friend = '".$friend."'";[/code]

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

Ray
Link to comment
Share on other sites

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

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

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

takes me to "sendMessage.php?friend="
why ...
Link to comment
Share on other sites

try


[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)){
$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>";
}
?>[/code]
Link to comment
Share on other sites

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

[code]<?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>";

}
?>[/code]

the button STILL takes me to "sendMessage.php?friend="
Link to comment
Share on other sites

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