Jump to content

Recommended Posts

I have the following code...

 

$num_rows = mysql_num_rows($rsSinglesMatch); //$num_rows now contains the number of rows from the query 
echo $num_rows;
if ($num_rows > 0 ) 
{ 
echo $ssPlayerNumber;
echo ("YEX");
}  
else
{	
echo "ROWS";
}	
$myrow = mysql_fetch_row($rsSinglesMatch);
//$rsSinglesMatches = mysql_fetch_assoc($rsSinglesMatch);
print_r($myrow);
//	if (!($rsSinglesMatches==0) || !($rsSinglesMatches_BOF==1))
if ($myrow > 0)
	{
	echo $myrow;
	}
else
	{
	echo "Rows not counted: ";
	}

 

And I can't get the mysql_num_rows and mysql_fetch_rows to work.

 

Currently it displays  Rows not counted:  and ROWS  if I ask it to display the number of rows it shows it as being 0.

 

Let me know if you see anything or if I need to post anything else.

Link to comment
https://forums.phpfreaks.com/topic/225424-why-is-mysql_num_rows-not-working/
Share on other sites

I have a query....

 

$rsSingles = "SELECT Count(match_results_singles.match_date AS match_date, match_results_singles.match_time, match_results_singles.match_result, match_results_singles.home_sets_won as my_wins, match_results_singles.visitor_sets_won as my_losses, locations.loc_name, players.Player_name, ' ' as supplies_balls FROM (match_results_singles INNER JOIN players ON match_results_singles.match_visiting_player = players.Player_number) INNER JOIN locations ON match_results_singles.match_location = locations.loc_code  WHERE (((match_results_singles.match_home_player)='{$ssPlayerNumber['player_number']}' )) UNION SELECT match_results_singles.match_date AS match_date, match_results_singles.match_time, match_results_singles.match_result, match_results_singles.visitor_sets_won as my_wins, match_results_singles.home_sets_won as my_losses, locations.loc_name, players.Player_name, '*' as supplies_balls FROM (match_results_singles INNER JOIN players ON match_results_singles.match_home_player = players.Player_number) INNER JOIN locations ON match_results_singles.match_location = locations.loc_code WHERE (((match_results_singles.match_visiting_player)='{$ssPlayerNumber['player_number']}' )) ORDER BY match_date)";
$rsSinglesMatch = mysql_query($rsSingles) or die (mysql_error());
$rsSinglesMatches = mysql_fetch_array($rsSinglesMatch);

 

sorry I forgot to post that earlier.

Okay thanks for your help....

 

The rest of the page is as follows:

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

<?PHP

while($rows=mysql_fetch_array($checkresults))

 

{

 

 

echo $rows['player_number'] ;

 

}

 

 

$num_rows = mysql_num_rows($rsSinglesMatch); //$num_rows now contains the number of rows from the query

echo $num_rows;

if ($num_rows > 0 )

{

echo $ssPlayerNumber;

echo ("YEX");

else

{

echo "ROWS";

}

$myrow = mysql_fetch_row($rsSinglesMatch);

//$rsSinglesMatches = mysql_fetch_assoc($rsSinglesMatch);

print_r($myrow);

// if (!($rsSinglesMatches==0) || !($rsSinglesMatches_BOF==1))

if ($myrow > 0)

{

echo $myrow;

}

else

{

echo "Rows not counted: ";

}

 

?>

<br>

 

 

</body>

</html>

 

 

That page still has no result sets, You have two different calls to result sets without the first query being made.  You provided a query earlier, but have failed to include it in this copy/paste.

 

Please post the entire page, including all queries.

<?PHP 
session_start();  
if (isset($_SESSION['user']))
{
$user = $_SESSION['user'];
$password = $_SESSION['password'];
}

else
{
//if the username is not passed then it goes back to the login page
header("location: /player_login.php");
}
$link = mysql_connect('localhost', 'root', ''); 

echo $user;
echo $password;

if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
} 

mysql_select_db("movedb")or die("Cannot Select Database");


//gets the current player number for the person logged in
$checkquery  = "Select player_number from players where Player_ID = '$user'";
$checkresults = mysql_query($checkquery) or die (mysql_error());


//select the rung number for the singles ladder
$checksingles = "Select rung_number from doubles_ladder where player_number = '$user'";
$checkifsingles = mysql_query($checksingles) or die (mysql_error());


$checkplayernumber  = "Select player_number from security where userid = '$user' AND password = '$password'";
$getplayernumber = mysql_query($checkplayernumber) or die (mysql_error());
$ssPlayerNumber=mysql_fetch_assoc($getplayernumber);


$query = "SELECT MAX(paid_thru) FROM players_paid where paid_type = '1' AND player_number = '{$ssPlayerNumber['player_number']}'";  
$result = mysql_query($query)or die ('Error in query: $query. ' . mysql_error());
$row = mysql_fetch_assoc($result);
$max = $row['MAX(paid_thru)'];

//converts the date to a more readable format
$max = $row['MAX(paid_thru)'] = date("M d, Y",strtotime($row['MAX(paid_thru)']));
echo "Ladder Membership Recently Expired on : " .$max. "!!!";

$rsSingles = "SELECT match_results_singles.match_date AS match_date, match_results_singles.match_time, match_results_singles.match_result, match_results_singles.home_sets_won as my_wins, match_results_singles.visitor_sets_won as my_losses, locations.loc_name, players.Player_name, ' ' as supplies_balls FROM (match_results_singles INNER JOIN players ON match_results_singles.match_visiting_player = players.Player_number) INNER JOIN locations ON match_results_singles.match_location = locations.loc_code  WHERE (((match_results_singles.match_home_player)='{$ssPlayerNumber['player_number']}' )) UNION SELECT match_results_singles.match_date AS match_date, match_results_singles.match_time, match_results_singles.match_result, match_results_singles.visitor_sets_won as my_wins, match_results_singles.home_sets_won as my_losses, locations.loc_name, players.Player_name, '*' as supplies_balls FROM (match_results_singles INNER JOIN players ON match_results_singles.match_home_player = players.Player_number) INNER JOIN locations ON match_results_singles.match_location = locations.loc_code WHERE (((match_results_singles.match_visiting_player)='{$ssPlayerNumber['player_number']}' )) ORDER BY match_date";
$rsSinglesMatch = mysql_query($rsSingles) or die (mysql_error());
$rsSinglesMatches = mysql_fetch_array($rsSinglesMatch);



?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?PHP 
while($rows=mysql_fetch_array($checkresults))

{


echo $rows['player_number'] ;

}


$num_rows = mysql_num_rows($rsSinglesMatch); //$num_rows now contains the number of rows from the query 
echo $num_rows;
if ($num_rows > 0 ) 
{ 
echo $ssPlayerNumber;
echo ("YEX");
}  
else
{	
echo "ROWS";
}	
$myrow = mysql_fetch_row($rsSinglesMatch);
//$rsSinglesMatches = mysql_fetch_assoc($rsSinglesMatch);
print_r($myrow);
//	if (!($rsSinglesMatches==0) || !($rsSinglesMatches_BOF==1))
if ($myrow > 0)
	{
	echo $myrow;
	}
else
	{
	echo "Rows not counted: ";
	}

?>
<br>


</body>
</html>

Sorry for the goof up...I just saw you wanted from query on...

Everything else seems to work except for the count of rows....

$rsSingles = "SELECT match_results_singles.match_date AS match_date, match_results_singles.match_time, match_results_singles.match_result, match_results_singles.home_sets_won as my_wins, match_results_singles.visitor_sets_won as my_losses, locations.loc_name, players.Player_name, ' ' as supplies_balls FROM (match_results_singles INNER JOIN players ON match_results_singles.match_visiting_player = players.Player_number) INNER JOIN locations ON match_results_singles.match_location = locations.loc_code  WHERE (((match_results_singles.match_home_player)='{$ssPlayerNumber['player_number']}' )) UNION SELECT match_results_singles.match_date AS match_date, match_results_singles.match_time, match_results_singles.match_result, match_results_singles.visitor_sets_won as my_wins, match_results_singles.home_sets_won as my_losses, locations.loc_name, players.Player_name, '*' as supplies_balls FROM (match_results_singles INNER JOIN players ON match_results_singles.match_home_player = players.Player_number) INNER JOIN locations ON match_results_singles.match_location = locations.loc_code WHERE (((match_results_singles.match_visiting_player)='{$ssPlayerNumber['player_number']}' )) ORDER BY match_date";
$rsSinglesMatch = mysql_query($rsSingles) or die (mysql_error());
$rsSinglesMatches = mysql_fetch_array($rsSinglesMatch); //<- DELETE THIS LINE;

 

$num_rows = mysql_num_rows($rsSinglesMatch); //$num_rows now contains the number of rows from the query
echo $num_rows;
if ($num_rows > 0 )
{
echo $ssPlayerNumber;
echo ("YEX");
} 
else
{   
   echo "ROWS";
}   
$myrow = mysql_fetch_row($rsSinglesMatch);
//$rsSinglesMatches = mysql_fetch_assoc($rsSinglesMatch);
print_r($myrow);
//   if (!($rsSinglesMatches==0) || !($rsSinglesMatches_BOF==1))
   if ($myrow > 0) //<- $myrow is an array, it will never be greater than 0. Rather try if(is_array($myrow))
      {
      echo $myrow; //<- you cannot echo an array, rather implode the array,  echo implode(' ',$myrow);
      }
   else
      {
      echo "Rows not counted: ";
      }
      
?>

 

 

Read ALL the comments.  Mine are in there.

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.