What is an efficient way to put the tree data into an array?
I followed the sitepoint tutorial to retrieve the tree data.
However, the tutorial only shows how to output the tree, not how to make a multidementional array.
I used
SELECT title, lft, rgt FROM tree_structure WHERE lft BETWEEN $parentLft AND $parentRgt ORDER BY lft ASC
So for each item, I have its title, left and right values.
I am stuck on making the array look like this
Array
(
Title: Main Topic
Children => Array
(
=> Title: subTopic
Leaf: true
=> Title: Another subtopic
Children => Array
(
=> Title: subtopic child
Leaf: true
)
)
)
If you could help, I would really appreciate it.
PS. The sql output looks like this (except I have title, not name and don't use category_id ):
+-------------+----------------------+-----+-----+
| category_id | name | lft | rgt |
+-------------+----------------------+-----+-----+
| 1 | ELECTRONICS | 1 | 20 |
| 2 | TELEVISIONS | 2 | 9 |
| 3 | TUBE | 3 | 4 |
| 4 | LCD | 5 | 6 |
| 5 | PLASMA | 7 | 8 |
| 6 | PORTABLE ELECTRONICS | 10 | 19 |
| 7 | MP3 PLAYERS | 11 | 14 |
| 8 | FLASH | 12 | 13 |
| 9 | CD PLAYERS | 15 | 16 |
| 10 | 2 WAY RADIOS | 17 | 18 |