1
votes

I'm trying to build a category/subcategory class with php & MySQL.
I am stuck with the following problem:

I want to make a selection of all categories in an ordered way like it's showed in the picture below. The table structure I've made is:

enter image description here

Can I build an SELECT * statement which will select these categories in that order?

1

1 Answers

3
votes

You need to index your tree. There are multiple means to do so, explained in Managing Hierarchical Data in MySQL.