lost-in-SO
lost-in-SO

Reputation: 75

MySQL table structure question

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.

Upvotes: 2

Views: 193

Answers (1)

Abe Miessler
Abe Miessler

Reputation: 85036

I usually use a structure similar to the one below:

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

MySQL has a decent article on this subject, Managing Hierarchical Data in MySQL, 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.

Upvotes: 3

Related Questions