Well, I've come up with another method using JOIN with the categories and items table:
PHP Code:
$sql = "
SELECT categories.*, COUNT(products.id) AS productcount
FROM categories
LEFT OUTER JOIN products ON (categories.level2id = products.cat1level2 OR categories.level2id = products.cat2level2)
WHERE level1id = '$level1id'
GROUP BY categories.level2id";
This is still taking just as long, up to 20-30 seconds for 100+ subcategories. Is this the way I'm supposed to be doing it or is there another way?
Thanks
EDIT:
In addition, even if I do something like this to JOIN categories/products tables without counting (and without grouping), it still takes just as long. Some parent categories might hold 100 sub-categories but only have 2 products total within all sub-categories, and it STILL takes 20-30 seconds:
PHP Code:
$sql = "
SELECT categories.*, products.id
FROM categories
LEFT OUTER JOIN products ON (categories.level2id = products.cat1level2 OR categories.level2id = products.cat2level2)
WHERE level1id = '$level1id'
Bookmarks