2

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

7 Comments

Exactly my thought, except for the annoying CamelCase.
+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
@Abe Miessler Is this the best way to display url values like index.php?cat=category&sub=sub-cat
It's the best way to store this information. How you display it is up to you and PHP.
@lost-in-SO, I'm not a big PHP guy so probably better to create a new question for that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.