Page 1 of 1

$num_rows not working: what have I done???

Posted: Thu May 27, 2010 5:10 am
by simonmlewis

Code: Select all

$result = mysql_query ("SELECT catid, catname FROM products WHERE pause = 'off' AND catid IS NOT NULL GROUP BY catname");
while ($row = mysql_fetch_object($result))
      {
      $count = mysql_query ("SELECT id, catid FROM products WHERE catid = '$row->catid");
      $num_rows = mysql_num_rows($count); 
      mysql_free_result($count);
      
			echo "<div class='submenu'";
			
      if ($c != NULL && $c == $row->catid) { echo "style='background-color:#FF7200; color: #ffffff'";}
			echo "><a href='index.php?page=categ&menu=sub&c=$row->catid&cname=$row->catname&head=$row->catname'>";
			
      if ($c == $row->catid) { echo "<font color='#000000'>$row->catname&nbsp;<font size='1'>($num_rows)</font></a></font>";} 
      elseif ($c != $row->catid) { echo "$row->catname&nbsp;<font size='1'>($num_rows)</font></a>";}
      echo "</div>";
        
        }
	mysql_free_result($result);
When I run it live I just get the () brackets around what should be a count.
When I run it locally I get this:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\phpMyAdmin\site\includes\menu\sub.inc on line 13

Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in C:\xampp\phpMyAdmin\site\includes\menu\sub.inc on line 15
Line 13 is

Code: Select all

      $num_rows = mysql_num_rows($count); 
Line 15 is empty.

I just need to have the category name, and the amount of items assigned to that category by each one.

Re: $num_rows not working: what have I done???

Posted: Thu May 27, 2010 5:25 am
by Eran
This is what happens when you don't check the results of the query. It is returning 'false'.
You have a missing single-quote at the end of the query, or alternatively, if catid is a number, you have a single-quote that is not needed in front of it.

Re: $num_rows not working: what have I done???

Posted: Thu May 27, 2010 5:26 am
by simonmlewis
Oh what a spanner.
Thanks!!