I'm writing a script at the moment that can have unlimited levels of categories
In the database I store the ID, ParentID, Title, Full Title etc...so an example top-level cat and subcat may look like this in the database:
1 1 Category_One Category_One
2 1 SubCategory Category_One/SubCategory
Now the problem Im having is that Im adding "galleries" to a seperate table and next to category names in the templates I want to show the number of galleries in each category. At the moment it is fine as I have a Total Column in the categories table and as you can see from the example above I can just increment the Total where the parentid equals one. However with three levels of categories it looks like:
1 1 Category_One Category_One
2 1 SubCategory Category_One/SubCategory
3 2 SubSubCat Category_One/SubCategory/SubSubCat
....I just totally can't figure out how to increment all totals for the categories in the tree above and including the category the gallery is being added to.
:(
In the database I store the ID, ParentID, Title, Full Title etc...so an example top-level cat and subcat may look like this in the database:
1 1 Category_One Category_One
2 1 SubCategory Category_One/SubCategory
Now the problem Im having is that Im adding "galleries" to a seperate table and next to category names in the templates I want to show the number of galleries in each category. At the moment it is fine as I have a Total Column in the categories table and as you can see from the example above I can just increment the Total where the parentid equals one. However with three levels of categories it looks like:
1 1 Category_One Category_One
2 1 SubCategory Category_One/SubCategory
3 2 SubSubCat Category_One/SubCategory/SubSubCat
....I just totally can't figure out how to increment all totals for the categories in the tree above and including the category the gallery is being added to.
:(