Fenhopi Posted May 16, 2010 Share Posted May 16, 2010 Hi, I'm working on a friend system for my website. I'm having some problems with the view pending friend requests page. The way I have it, is if status is: 0=Friendship requested by another user, 1=already in a friendship. "status" is an INT column in my database. So I did this: $status = "SELECT status FROM friends2 WHERE user2='$username'"; $test = $database->query($status); //If user is 0 (not a friend) then display him and give options to accept or deny request if($test == '0'){ for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"user1"); echo "<a href=\"userinfo.php?user=$uname\"><h3>$uname</h3></a>has requested to become your friend "; echo "<a href=\"accept.php\">Accept</a> "; echo "<a href=\"reject.php\">Reject</a><br><br>"; } } else{ echo "No pending requests"; } } I'm not getting any errors, but it's obvious that it does not understand my if statement. Please help me find a solution. Thank you. Link to comment https://forums.phpfreaks.com/topic/201988-problems-calling-a-mysql-query-with-php/ Share on other sites More sharing options...
ldb358 Posted May 17, 2010 Share Posted May 17, 2010 your checking whether the object == 0 you need to add: $test = $database->query($status); $row = $test->fetch_object(); if($row->status == '0'){ Link to comment https://forums.phpfreaks.com/topic/201988-problems-calling-a-mysql-query-with-php/#findComment-1059262 Share on other sites More sharing options...
Fenhopi Posted May 17, 2010 Author Share Posted May 17, 2010 Thanks for your reply! When I did that I got this error: "Fatal error: Call to a member function fetch_object() on a non-object in viewfriendreq.php on line 66" Line 66 is the: $row = $test->fetch_object(); Link to comment https://forums.phpfreaks.com/topic/201988-problems-calling-a-mysql-query-with-php/#findComment-1059270 Share on other sites More sharing options...
ldb358 Posted May 17, 2010 Share Posted May 17, 2010 try adding: $test = $database->query($status); echo $database->error; //check if there is a mysql error var_dump($test); //check if its returning an object Link to comment https://forums.phpfreaks.com/topic/201988-problems-calling-a-mysql-query-with-php/#findComment-1059277 Share on other sites More sharing options...
Fenhopi Posted May 17, 2010 Author Share Posted May 17, 2010 The error said this now: " resource(16) of type (mysql result) Fatal error: Call to a member function fetch_object() on a non-object in /Users/Fenhopi/Sites/viewfriendreq.php on line 69" Link to comment https://forums.phpfreaks.com/topic/201988-problems-calling-a-mysql-query-with-php/#findComment-1059288 Share on other sites More sharing options...
ldb358 Posted May 17, 2010 Share Posted May 17, 2010 try: $test = $database->query($status); $row = mysql_fetch_array($test); if($row['status'] == '0'){ if that doesn't work what mysql class are you using? Link to comment https://forums.phpfreaks.com/topic/201988-problems-calling-a-mysql-query-with-php/#findComment-1059289 Share on other sites More sharing options...
Fenhopi Posted May 17, 2010 Author Share Posted May 17, 2010 That works! Thank you very much, sir. Link to comment https://forums.phpfreaks.com/topic/201988-problems-calling-a-mysql-query-with-php/#findComment-1059292 Share on other sites More sharing options...
Fenhopi Posted May 17, 2010 Author Share Posted May 17, 2010 Another thing, it seems that if the first number in my database table is 1 he returns "No pending requests", instead of ignoring that and check if the next one is 0. Any ideas? Link to comment https://forums.phpfreaks.com/topic/201988-problems-calling-a-mysql-query-with-php/#findComment-1059293 Share on other sites More sharing options...
ldb358 Posted May 17, 2010 Share Posted May 17, 2010 i dont get what your asking i guess because if the value != 0 that is what it is supposed to output Link to comment https://forums.phpfreaks.com/topic/201988-problems-calling-a-mysql-query-with-php/#findComment-1059304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.