Helping ordinary people create extraordinary websites!
   

How to count all listings in a Category in PHP?

Thursday, 10th September 2009
by cgiFX


How can I count all the listings in a categoryincluding all the listings in all that category's subcategories without knowing the number of subcategories there are using PHP?





phpdreams
You would need a recursive function, that is, a function that can call itself.

function categoryCount($thisCat) {
global $catCount;
// loop thru $thisCat counting listings
// if the listing has sub-categories, call categoryCount() again for it.
// when you're done, $catCount will have the total count in it.

}

call it initially with the ID of the category you want a count from.

A bit rough, but hopefully it'll give you the idea.
Friday, 9th October 2009
Votes:
26
13

More PHP Help:
» Where can I find a good PayPal PHP script?
» Creating new login in php
» Where can I find a script for uploading an sql file to a MySQL database server?
» Splash screen
» Can anyone write a php code for greatest of three nos using if else?
» What is the use of extract($_REQUEST);
» Is there a PHP Left function Left()?
» How to remove all characters except letters from a string?