tags:

views:

33

answers:

1

I've been looking around on SO and have been seeing a lot of questions about category tree menus and was wondering how would my MySQL table or tables look like so I can add many categories and count less sub categories and display them on my web site.

Note I will be using PHP & MySQL.

+3  A: 

I usually use a structure similar to the one below:

Category
--------
CategoryId
CategoryName
ParentCategoryId

MySQL has a decent article on this subject here if you are interested in doing some more research on the subject. It goes into this structure and gives you some sample queries on how to get the data you want for specific scenarios.

Abe Miessler
Exactly my thought, except for the annoying CamelCase.
GuidoH
Don't tell me you're an underscore person....
Abe Miessler
+1: I've been known to use both--at the same time! :) Cool link, but MySQL's lack of hierarchical/recursive query support makes me instinctively recommend Oracle/SQL Server/PostgreSQL
OMG Ponies
lost-in-SO
It's the best way to store this information. How you display it is up to you and PHP.
Abe Miessler
@Abe Miessler how would I display it using php or is that another question to be posted by itself.
lost-in-SO
@OMG Ponies - I agree. @lost-in-SO, your life will probably be easier if you have the option of using one of these DBMS'.
Abe Miessler
@lost-in-SO, I'm not a big PHP guy so probably better to create a new question for that.
Abe Miessler