Jump to content

mysql_num_rows not working


Recommended Posts

while($row10000=mysql_fetch_array($result10000)){
$product_id3=$row10000['product_id'];
$sql15000="SELECT * FROM $tbl_name WHERE product_id=".$product_id3;
$result15000=mysql_query($sql15000);
while($row15000=mysql_fetch_array($result15000)){
extract($row15000);
if(mysql_num_rows($result15000)==0){
$content='<div class="center">Search found no results.</div>';
}
else{
$content.=$product_name;
}
}
}

 

The above does not display the $content variable when there are no rows returned, just comes up with a blank page. Works fine when there are results returned.

 

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

That is how it should work, as the while statement will never run, being that it will return false on row 0.

 

You MUST put the mysql_num_rows() function BEFORE the while statement.

 

That's what I figured... was just to lazy to change it to try it myself.

 

 

EDIT: Just tried it, still a blank page.

while($row10000=mysql_fetch_array($result10000)){
$product_id3=$row10000['product_id'];
$sql15000="SELECT * FROM $tbl_name WHERE product_id=".$product_id3;
$result15000=mysql_query($sql15000);
if(mysql_num_rows($result15000)==0){
$content='<div class="center">Search found no results.</div>';
}
else{
while($row15000=mysql_fetch_array($result15000)){
extract($row15000);
$content.=$product_name;
}
}
}

Well turned on error reporting and all I'm getting is notices that I have an Undefined Index and that the Content variable is undefined (because it's being called but nothing's a signed to it, for whatever reason.

 

 

The page is actually displayed properly when the keyword exists, just when there are no results returned does it not show anything.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.