Jump to content

Recommended Posts

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.  :)

Link to comment
https://forums.phpfreaks.com/topic/119987-mysql_num_rows-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/119987-mysql_num_rows-help/#findComment-618061
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.