I need to create a tree of a multi-level category structure, complete with a checkbox for each category, based on data from one MySQL table.
mysql> SELECT ID, ParentID FROM ProductCategories;
The result:
| ID | ParentID |
|----------------|
| 1 | 0 |
| 2 | 0 |
| 3 | 0 |
| 4 | 0 |
| 5 | 0 |
| 6 | 0 |
| 7 | 0 |
| 8 | 0 |
| 9 | 1 |
| 10 | 1 |
| 11 | 1 |
| 12 | 1 |
| 13 | 1 |
| 14 | 1 |
| 15 | 9 |
| 16 | 9 |
| 17 | 9 |
| 18 | 9 |
| 19 | 9 |
| 20 | 9 |
| 21 | 9 |
| 22 | 9 |
| 23 | 9 |
| 24 | 9 |
| 25 | 2 |
| 26 | 2 |
| 27 | 2 |
For instance, all categories with a ParentID of 1
would appear indented under the category with an ID of 1
.
I suppose I'll need to create a multi-dimensional array, and then loop through it to create the list, but I'm a bit lost as to how to go about it.