Category and subcategory via 'activeSelect'
Wed, 07/21/2010 - 15:07
I'm just not thinking very clearly today because I'm sure I've done something like this before...
I have a Project table that needs to be classified with a 'category' an a 'sub-category'. The sub-category items depend on which category is chosen. Ideally, this will use JS so that when a category is chosen via a select box, the sub-category select items will update accordingly.
What's the best way to represent this in the db?
thanks,

I'm assuming that you have a strict 2-level hierarchy: every project subcategory belongs to exactly one category.
If that's the case, you probably want:
Table Project:
ProjectID
ProjectName
SubCategoryID (foreign key into the sub-categories table)
Table SubCategory:
SubCategoryID
CategoryID (foreign key into the categories table)
SubCategoryName
Table Category:
CategoryID
CategoryName
Yes, that is close. The project needs a category as well though. How do I accomodate that?
If every Project belong to SubCategory and every SubCategory belong to Category then every Project belong to Category as well (wia the SubCategory table).
Project -> SubCategory -> Category
Brynjar