Mutley Posted August 16, 2008 Share Posted August 16, 2008 Hi there, I have a problem with the code below. If the query returns zero rows/results. I do not want the button to show. But I just can't get it to work. <?php $result = mysql_query("SELECT team_id, owner FROM teams WHERE owner = '$user_id' LIMIT 1"); while($row = mysql_fetch_array( $result )) { $team_id = $row['team_id']; $result_inv = mysql_query("SELECT id FROM teams_inv WHERE user_id = '$id' AND team_id = $team_id LIMIT 1"); while($row_inv = mysql_fetch_array( $result_inv )) { if(mysql_num_rows($result_inv)==0){ $already_invited = 'true'; } } if($row['owner'] != '0' && $row['owner'] != $id && $already_invited == 'true') { ?> <form action="teams.php" method="post"> <input type="hidden" name="invite" value="<?=$id?>" /> <input type="submit" name="submit" value="Invite to Team" /> </form> <?php } } ?> I've tried == and != but they don't seem to make any difference to it working or not. One makes it always show, the other makes it never show. The other statements in the IF work correctly. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/119987-mysql_num_rows-help/ Share on other sites More sharing options...
budimir Posted August 16, 2008 Share Posted August 16, 2008 Yes, and it's working proprely. You need to use else { some code } You did'nt tell the program what to do after, it's just showing true or not showing. Quote Link to comment https://forums.phpfreaks.com/topic/119987-mysql_num_rows-help/#findComment-618053 Share on other sites More sharing options...
Mutley Posted August 16, 2008 Author Share Posted August 16, 2008 Thanks, but if it shows true, it should show, if it isn't true, it doesn't show. I shouldn't need an else? ??? Quote Link to comment https://forums.phpfreaks.com/topic/119987-mysql_num_rows-help/#findComment-618055 Share on other sites More sharing options...
budimir Posted August 16, 2008 Share Posted August 16, 2008 Try this if(mysql_num_rows($result_inv)>0){ $already_invited = 'true'; And also put your form in echo Quote Link to comment https://forums.phpfreaks.com/topic/119987-mysql_num_rows-help/#findComment-618059 Share on other sites More sharing options...
PFMaBiSmAd Posted August 16, 2008 Share Posted August 16, 2008 The following code is inside the while() loop - if(mysql_num_rows($result_inv)==0){ $already_invited = 'true'; } The while() loop will only execute the code inside of it when a row existed and was fetched by mysql_fetch_array(). mysql_num_rows($result_inv) will never be equal to zero inside of the while() loop. You need to fix your logic so that you do the mysql_num_rows() logic before the start of the while() loop. Quote Link to comment https://forums.phpfreaks.com/topic/119987-mysql_num_rows-help/#findComment-618061 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.