runnerjp Posted May 27, 2008 Share Posted May 27, 2008 ok at the moment i have this set up in my db i have friendname username so i currently use <?php $get_username_value = get_username($id); $query = "SELECT * FROM `friends` WHERE `username` = '$get_username_value'"; ?> to get a username out who the perosn is friends with... but then i go the the friendsname profile it displays there name and not the username form "username" ( the person who ask them to be added) how can i combat this? Quote Link to comment https://forums.phpfreaks.com/topic/107507-getting-friends-from-db/ Share on other sites More sharing options...
DarkWater Posted May 27, 2008 Share Posted May 27, 2008 Please elaborate a bit. o-o Quote Link to comment https://forums.phpfreaks.com/topic/107507-getting-friends-from-db/#findComment-551069 Share on other sites More sharing options...
jonsjava Posted May 27, 2008 Share Posted May 27, 2008 you have a function called get_username? aside from that, it should be something like this: <?php $query = "SELECT * FROM `friends` WHERE `username`='{$get_username_value}';"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $friends = $row['friendname']; print $friends; ?> Quote Link to comment https://forums.phpfreaks.com/topic/107507-getting-friends-from-db/#findComment-551071 Share on other sites More sharing options...
runnerjp Posted May 27, 2008 Author Share Posted May 27, 2008 humm this code <?php $query = "SELECT * FROM `friends` WHERE `username`='{$get_username_value}';"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $friends = $row['friendname']; print $friends; ?> prints the 1st name in my db only but on every profile... Quote Link to comment https://forums.phpfreaks.com/topic/107507-getting-friends-from-db/#findComment-551078 Share on other sites More sharing options...
jonsjava Posted May 27, 2008 Share Posted May 27, 2008 <?php $query = "SELECT * FROM `friends` WHERE `username`='{$get_username_value}';"; $result = mysql_query($query); $friends = ""; while ($row = mysql_fetch_assoc($result)){ $friends .= $row['friendname'].", "; } print $friends; ?> Quote Link to comment https://forums.phpfreaks.com/topic/107507-getting-friends-from-db/#findComment-551079 Share on other sites More sharing options...
runnerjp Posted May 27, 2008 Author Share Posted May 27, 2008 ahh ok yes that works... BUT is there away to work it the other way around sooo friendname username runnerjp jonsjava jonsjava is friends with runnerjp so on jonsjava profile display runnerjp as a friend but runnerjp is also firends with jonsjava so display jonsjava on runnerjps profile Quote Link to comment https://forums.phpfreaks.com/topic/107507-getting-friends-from-db/#findComment-551091 Share on other sites More sharing options...
runnerjp Posted May 27, 2008 Author Share Posted May 27, 2008 also how would i get this to work properly <?php session_start(); require_once '../settings.php'; checkLogin ('1 2'); $query = "SELECT * FROM `friends` WHERE `username`= '$username';"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ $friends= $row['friendname']; } $sql = "SELECT image FROM users WHERE username = '$friends'"; $result = mysql_db_query($database,$sql,$connection) or die(mysql_error().'<br />Query was:'.$sql); while($row = mysql_fetch_assoc($result)){ $image = $row["image"]; } echo $friends; echo $image; ?> Quote Link to comment https://forums.phpfreaks.com/topic/107507-getting-friends-from-db/#findComment-551133 Share on other sites More sharing options...
runnerjp Posted May 28, 2008 Author Share Posted May 28, 2008 bmp Quote Link to comment https://forums.phpfreaks.com/topic/107507-getting-friends-from-db/#findComment-551463 Share on other sites More sharing options...
runnerjp Posted May 28, 2008 Author Share Posted May 28, 2008 can any 1 yet tell me how i could pull both name or would i have to do something like this |id| username | ... | friends| | 1|user1 | ... | 2,9,13| | 2|user2 | ... | 1,8,12| User 1 would be friends with users 2, 9, and 13. User 2 would be friends with users 1, 8, and 12. Quote Link to comment https://forums.phpfreaks.com/topic/107507-getting-friends-from-db/#findComment-551525 Share on other sites More sharing options...
BlueSkyIS Posted May 28, 2008 Share Posted May 28, 2008 that's similar to how handshakes does it www.dzoic.com Quote Link to comment https://forums.phpfreaks.com/topic/107507-getting-friends-from-db/#findComment-551578 Share on other sites More sharing options...
runnerjp Posted May 28, 2008 Author Share Posted May 28, 2008 so does that mean thats the way i should do it Quote Link to comment https://forums.phpfreaks.com/topic/107507-getting-friends-from-db/#findComment-551646 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.