Category and subcategory via 'activeSelect'

Login or register to post comments
3 replies [Last post]
cliff's picture
Offline
Joined: 04/11/2008

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,

alex94040's picture
Offline
Joined: 11/06/2008

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

cliff's picture
Offline
Joined: 04/11/2008

Yes, that is close. The project needs a category as well though. How do I accomodate that?

Offline
Joined: 03/31/2008

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