Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Category Counting 1

Status
Not open for further replies.

shop73

IS-IT--Management
May 13, 2007
48
0
0
BA
How with Dreamweaver make category counting like

Digital camera (5)
Computers (3)
Cars (0)
....


I have two tables, categories and products

categories: categoryID, categoryName
products: prodID, prodName, categoryID

 
Code:
$result = mysql_query("select C.categoryname, count(P.prodname) as prodcount from categories as C join products as P on p.categoryid = C.categoryid group by C.categoryname");

while ($rows = mysql_fetch_assoc($result)) {
echo $rows("categoryname);
echo "(";
echo $rows("prodcount");
echo ")";
echo "<br>";
echo "\n";
}
mysql_free_result($result)

looks about right,
NOTE no connection and NO error checking done.


Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
How to show category with zero products?

cars (0)
 
Thank You very much!

This works.

Carduel
 
Chris,

in table products I have prodShow (enum, Y, N, Required). How to add this item in sql query to show all categories, product counting for products with sign 'Y' in prodShow field?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top