scottjcampbell Posted August 25, 2008 Share Posted August 25, 2008 Hi, i have been trying this for some time now, i will try my best to explain, but i am not very good at it. I have a friends system on my website, that works fine, once a user accepts a friend request, their name, and the person who wants to be friends with the are put into a table like this: I am now trying (And Failing) to make a script which will display a certain message if the user is friends with the person who's profile they are viewing, here is my code so far: $username = $_SESSION['username']; $q = "SELECT username,friendname FROM friends WHERE `username` = $requser"; $result = $database->query($q); /* Display table contents */ for($i=0; $i<$num_rows; $i++){ $fname = mysql_result($result,$i,"friendname"); } if ($fname==$requser){ echo "YES!"; }else{ echo "NO!"; } But i am always getting "YES!" even if they are not friends. Variables: $requser is defined in the title of the profile (e.g domain.com/profile.php?user=test) $username is the person who is viewing the profile So i wanted to make it that if $username (Viewer) is friends with $requser (Person who's profile they are viewing) then thry will see"Yes!", otherwise, they will see "No!" P.S DATABASE CREDENTIALS ARE DEFINED ABOVE IN THE CODE Link to comment https://forums.phpfreaks.com/topic/121272-solved-check-if-record-exists/ Share on other sites More sharing options...
budfroggy Posted August 25, 2008 Share Posted August 25, 2008 Use mysql_num_rows (http://us3.php.net/mysql_num_rows) to find out how many rows were selected. If it was 0, they arent friends, otherwise, they are friends. Link to comment https://forums.phpfreaks.com/topic/121272-solved-check-if-record-exists/#findComment-625252 Share on other sites More sharing options...
scottjcampbell Posted August 25, 2008 Author Share Posted August 25, 2008 Thanks, with your help, i have now completed this script. Link to comment https://forums.phpfreaks.com/topic/121272-solved-check-if-record-exists/#findComment-625264 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.