jigsawsoul Posted March 22, 2010 Share Posted March 22, 2010 Hey Guys I'm not really sure where to start, but i have a number of products within my products table, which all fall under different types of categories. So i have two tables, products and categories which both have a relationship, so I can tell which products below in which categorie. So i want to display a navigation of the categories and how many products are in that categorie. e.g. Apple Laptops (3) Apple Desktops (9) PC Laptops (4) Etc... does anyone have an idea on where to start, or how this would be created. Anything would be a good help.. Thanks. p.s. anymore information needed just ask.. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/196119-counting-the-number-of-categories-how-to/ Share on other sites More sharing options...
phant0m Posted March 22, 2010 Share Posted March 22, 2010 Try this: SELECT c.*, COUNT(*) FROM categories c LEFT JOIN products p ON c.id = p.categoriesid GROUP BY c.id Quote Link to comment https://forums.phpfreaks.com/topic/196119-counting-the-number-of-categories-how-to/#findComment-1029975 Share on other sites More sharing options...
jigsawsoul Posted March 22, 2010 Author Share Posted March 22, 2010 Ah, sorry dude, this doesn't really mean anything to me.. little help lol Quote Link to comment https://forums.phpfreaks.com/topic/196119-counting-the-number-of-categories-how-to/#findComment-1029978 Share on other sites More sharing options...
Maq Posted March 22, 2010 Share Posted March 22, 2010 Do you need help with the PHP, the SQL query or both? Quote Link to comment https://forums.phpfreaks.com/topic/196119-counting-the-number-of-categories-how-to/#findComment-1029985 Share on other sites More sharing options...
jigsawsoul Posted March 22, 2010 Author Share Posted March 22, 2010 I have this code below it displays the categories in the navigation fine. But where it says (0) i want to display the amount of products in my products.table where categories is equal to the id.. any ideas on how to do this? <?php $result = "SELECT * FROM categories"; $result = mysql_query ($result) or die (mysql_error()); while($row = mysql_fetch_assoc($result)) { $categories .= ' <li><a href="categorie.php?id='.$row['id'].'">'.$row['categorie'].' (0)</a></li> '; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/196119-counting-the-number-of-categories-how-to/#findComment-1030002 Share on other sites More sharing options...
jigsawsoul Posted March 22, 2010 Author Share Posted March 22, 2010 bump? Quote Link to comment https://forums.phpfreaks.com/topic/196119-counting-the-number-of-categories-how-to/#findComment-1030051 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.