Hi,
I have 2 tables, articles and categories
Everytime an article is created a category or subcategory is assigned to it
My category table is structured to have subcategories.
catid | parentid | parentlist
1 |0 |1
3 |1 |3,1
4 |3 |4,3,1
catid 1 with parentid 0 is a top category.
How can I retrieve article count and assign them to their cat and parents.
e.g if I set catid 4 to an article
I'd like to adjust the count in catid 4, 3 and 1
Instead of doing a catcount + 1, I had rather select count(*) FROM articles WHERE catid IN(parentlist) and then update the appropriate categories so the top level has all count from itself + its sublevels, the sublevel has all count in itself + its sublevels, and finally the last sublevel has only its count.
Example: If I add an article and assign it to subcat 4
then subcat updates count for all articles with subcat 4
all articles having subcat 4,3 in subcat 3
and finally the top cat will have the count in 4,3,1
I want to do it like that because it's more accurate as sometimes articles get deleted or get moved to other category.
Thank you.