techiefreak05 Posted August 28, 2006 Share Posted August 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
craygo Posted August 28, 2006 Share Posted August 28, 2006 You could have a table which links id'sjust 2 fieldsidfriendidso when they log in you will have the id then just query this table to get the id's of their friendsRay Quote Link to comment Share on other sites More sharing options...
shocker-z Posted August 28, 2006 Share Posted August 28, 2006 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'sRegardsLiam Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 28, 2006 Author Share Posted August 28, 2006 so i did something like this in phpMyAdmin. is this on the right track?[code]CREATE TABLE `friends` (`username` VARCHAR( 31 ) NOT NULL ,`friend` VARCHAR( 31 ) NOT NULL ) TYPE = MYISAM ;[/code] Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 28, 2006 Author Share Posted August 28, 2006 I think I get it .. well I do :-P but how would I add a row when they add a user as a friend?? Quote Link to comment Share on other sites More sharing options...
craygo Posted August 28, 2006 Share Posted August 28, 2006 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 longRay Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 28, 2006 Author Share Posted August 28, 2006 they cant change their username, so i wont run into that prob :P Quote Link to comment Share on other sites More sharing options...
craygo Posted August 28, 2006 Share Posted August 28, 2006 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 stuffRay Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 28, 2006 Author Share Posted August 28, 2006 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 ... Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 28, 2006 Author Share Posted August 28, 2006 I guess I didnt need to show the form code .. nothing is wrong with that Quote Link to comment Share on other sites More sharing options...
shocker-z Posted August 28, 2006 Share Posted August 28, 2006 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] Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 28, 2006 Author Share Posted August 28, 2006 in the sendMesage.php?friend= ....I want the textbox called "to", to be filled with the value of "friend"heres the "to" code[code]<input type="text" name="to" value="<? echo $_GET[friend]; ?>"[/code]and "to" is never filled with anything! help!! Quote Link to comment Share on other sites More sharing options...
shocker-z Posted August 28, 2006 Share Posted August 28, 2006 That's because your using POST in your form change<form action="" method="post">to<form action="" method="get"> Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 28, 2006 Author Share Posted August 28, 2006 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=" Quote Link to comment Share on other sites More sharing options...
shocker-z Posted August 28, 2006 Share Posted August 28, 2006 because you have nothing with the value of the get in your submitting the form changeecho "<form action='' method='get'><a href='sendMessage.php?friend='" .$friend. "'><input type='submit' name='friend' value='-Send Message-'></a></form>";toecho "<a href='sendMessage.php?friend='" .$friend. "'>Send Message</a>";That will do the job :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.