0

I am currntly working on a category structure, which has to be build from an MySQL table. My table will look approximately like this:

ID | Name                | ParentID
---+---------------------+---------
 1 | Fruits              | 0
 2 | Apples              | 1
 3 | Bananas             | 1
 4 | Cars                | 0
 5 | Chevrolet           | 4
 6 | Aston Martin        | 4
 7 | Something           | 0
 8 | Something more      | 0
 9 | Test category       | 8
10 | Below test          | 9

How can I make this multi-level, so I can use it for creating e.g. menus, drop-downs and so on?

Thanks in advance,

denlau

denlau
  • 916
  • 2
  • 9
  • 21
  • 2
    Just one of the many, many answers to this question - http://stackoverflow.com/questions/7884337/how-to-create-multi-dimensional-array-from-a-list?rq=1 – Mark Baker Sep 13 '13 at 16:19
  • It already is multi-level as you have a parent id for each entry – Andy Gee Sep 13 '13 at 16:28
  • Well, the array isn't created - but has to be made recursive. I've found this topic, which I actually prefer - because of the performance: http://stackoverflow.com/questions/11239652/php-create-a-multidimensional-array-from-an-array-with-relational-data/11240578#11240578 – denlau Sep 13 '13 at 17:00

0 Answers0