Jump to content


Counting Errors :(

  • Please log in to reply
3 replies to this topic

#1 lpxxfaintxx

  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 17 June 2006 - 08:07 PM


As a lot of you may know, I am working on a tutorial CMS. When I list all the tutorial categories, I try to add how many tuts are in it. I used the following:

    <div id="menu">
      <div class="sideheader">Tutoial Categorgies</div>

$sql = "SELECT * FROM `category` order by category";
$cat = $rows["category"];
$catid = $rows["cat_id"];

$sqlc = "SELECT * FROM `tutorials` WHERE `catid` = '$catid'";
$queryc = mysql_query($sqlc);
while($rowc = mysql_fetch_array($queryc))
$num_rowsc = mysql_num_rows($queryc);

echo <<<__HTML_END

<li><a href="viewcat.php?act=maincat&id=$catid">$cat ($num_rowsc)</a></li>



The categories list perfectly, except for one thing. The counting is messed up... it shows 1 more than there really is, and sometimes it shows 4 when there's none in the category!

For example, at [a href=\"http://informedia.ws/projects/tuts/viewcat.php?act=maincat&id=1\" target=\"_blank\"]http://informedia.ws/projects/tuts/viewcat...ct=maincat&id=1[/a] there are clearly 3 tutorials, but if you look to the left, it says there are "4"

Now try to click on "ASP Coding." There is no tutorials in that category, as you can see... but it shows on the left that it has 4.

Something went totally wrong, can anyone help me out here?


#2 klaroen

  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 17 June 2006 - 08:32 PM

you haven't got a '{' thing after your second while...

#3 Fyorl

  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 17 June 2006 - 10:44 PM

[!--quoteo(post=385084:date=Jun 17 2006, 03:32 PM:name=klaroen)--][div class=\'quotetop\']QUOTE(klaroen @ Jun 17 2006, 03:32 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
you haven't got a '{' thing after your second while...

1. If that was an issue then he would have received a parse error which he clearly hasn't
2. Curly braces are not needed for one line of code (although I tend to use them anyway)

I doubt this is your problem but I don't think your second while loop is necessary as mysql_num_rows() counts all the rows returned by the query. You could also try using the COUNT(*) function in SQL but that would require an extra query.

Don't worry, the printer fairies will sort it out.

#4 lpxxfaintxx

  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 19 June 2006 - 01:52 PM

Ok, thanks.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users