jigsawsoul Posted March 24, 2010 Share Posted March 24, 2010 any help would be great thanks Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE categories_id = '1'' at line 1 <?php $result = "SELECT * FROM categories"; $result = mysql_query ($result) or die (mysql_error()); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $query = "SELECT categories_id, COUNT(categories_id) FROM products GROUP BY categories_id WHERE categories_id = '$id'"; $query = mysql_query ($query) or die (mysql_error()); $number = mysql_fetch_assoc($result); $categories .= ' <li><a href="categorie.php?id='.$row['id'].'">'.$row['categorie'].' ('.$number['COUNT(categories_id)'].')</a></li> '; } ?> <div class="CommHolder"> <h1>Categories</h1> <div class="categories"> <ul> <?php echo $categories ?> </ul> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/196369-error-trying-to-count-rows-help-please/ Share on other sites More sharing options...
premiso Posted March 24, 2010 Share Posted March 24, 2010 The WHERE clause needs to be after the FROM tablename Quote Link to comment https://forums.phpfreaks.com/topic/196369-error-trying-to-count-rows-help-please/#findComment-1031065 Share on other sites More sharing options...
jigsawsoul Posted March 24, 2010 Author Share Posted March 24, 2010 Doesn't work the result i get is; Mac Laptops () PC laptops () When i should have Mac Laptops (1) Mac Desktops (2) PC Laptops (1) PC Desktops (2) anyone know where i going wrong or if i'm doing this write <?php $result = "SELECT * FROM categories"; $result = mysql_query ($result) or die (mysql_error()); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $query = "SELECT categories_id, COUNT(categories_id) FROM products WHERE categories_id = '$id' GROUP BY categories_id"; $query = mysql_query ($query) or die (mysql_error()); $number = mysql_fetch_assoc($result); $categories .= ' <li><a href="categorie.php?id='.$row['id'].'">'.$row['categorie'].' ('.$number['COUNT(categories_id)'].')</a></li> '; } ?> <div class="CommHolder"> <h1>Categories</h1> <div class="categories"> <ul> <?php echo $categories ?> </ul> </div> </div> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/196369-error-trying-to-count-rows-help-please/#findComment-1031067 Share on other sites More sharing options...
jigsawsoul Posted March 24, 2010 Author Share Posted March 24, 2010 really no one? Quote Link to comment https://forums.phpfreaks.com/topic/196369-error-trying-to-count-rows-help-please/#findComment-1031080 Share on other sites More sharing options...
hoogie Posted March 24, 2010 Share Posted March 24, 2010 Shouldn't this line: $number = mysql_fetch_assoc($result); read like this? $number = mysql_fetch_assoc($query); Quote Link to comment https://forums.phpfreaks.com/topic/196369-error-trying-to-count-rows-help-please/#findComment-1031103 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.