Jump to content

Warning: mysql_num_rows() supplied argument is not a valid MySQL result resource


MidOhioIT

Recommended Posts

This may be simple I just may need another pair of eyes..

 

When i get records back the below code works just fine, when I get 0 rows back it shows the warning below.  As you can see I tried to code for it and you can see that the code works as it echo's my message but I want the warning to go away

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in show_coupon_list.php on line 224

No Coupons for this Catogory or Business. Please let us know about the Category that displayed no results so we can contact businesses for you!

 

$cat_coupons =   mysql_query("SELECT a.business_name, a.seq_id, a.state, a.city 
FROM users a  where a.seq_id = '$cat_coupons_seq_id'");

 

$cat_num=mysql_num_rows($cat_coupons);
if ($cat_num > 0)
   {
     while ($row = mysql_fetch_array($cat_coupons))
         {	                                
           $business_name = $row["business_name"];
           $business_id = $row["seq_id"];
           $state       = $row["state"];
           $city       = $row["city"];
echo"<tr>   
    <td align = 'left'>  <a href=show_coupon.php?business=".urlencode($business_name).">$business_name     $city,$state </a></td>
            </tr>";
  }
   }
  else
    echo"<tr> 
          <td>No Coupons for this Catogory or Business. Please let us know about the Category that 
             displayed no results so we can contact businesses for you!
          </td>	
</tr>";

The error you are getting means that your query failed to execute. Echo mysql_error() to find out why.

 

A query that executes but returns zero rows DOES NOT produce any mysql_ function errors (unless you have the misfortune of using mysql_result()).

that makes since, thank you!  I had to move where im doing the count to where im doing the sql since there are some instances that the sql will not run as it depends on a record set back from another sql first.  I am not getting the errors now, thank you both...

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.