lpxxfaintxx Posted June 17, 2006 Share Posted June 17, 2006 Hi,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:[code] <div id="menu"> <div class="sideheader">Tutoial Categorgies</div> <ul><?php$sql = "SELECT * FROM `category` order by category";$result=mysql_query($sql);while($rows=mysql_fetch_array($result)){$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>__HTML_END;}[/code]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?Regards Quote Link to comment Share on other sites More sharing options...
klaroen Posted June 17, 2006 Share Posted June 17, 2006 you haven't got a '{' thing after your second while... Quote Link to comment Share on other sites More sharing options...
Fyorl Posted June 17, 2006 Share Posted June 17, 2006 [!--quoteo(post=385084:date=Jun 17 2006, 03:32 PM:name=klaroen)--][div class=\'quotetop\']QUOTE(klaroen @ Jun 17 2006, 03:32 PM) [snapback]385084[/snapback][/div][div class=\'quotemain\'][!--quotec--]you haven't got a '{' thing after your second while...[/quote]1. If that was an issue then he would have received a parse error which he clearly hasn't2. 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. Quote Link to comment Share on other sites More sharing options...
lpxxfaintxx Posted June 19, 2006 Author Share Posted June 19, 2006 Ok, thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.