Tree structures...
| From: | phobo | Date: | Sat, 24 Mar 2001 11:27:39 +0000 |
| Subject: | Tree structures... | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-7748@lists.php.net to get a copy of this message | ||
What's the best way to deal with tree structures? Use the following setup in
a database as an example:
ID | Parent | Description
------------------------
1 | | Colours
2 | 1 | Red
3 | | Hello
4 | 1 | Green
5 | 4 | Light
6 | 4 | Dark
This should be represented as:
1. Colours
4. +--Green
6. +--Dark
5. +--Light
2. +--Red
3. Hello
(ie, in tree structure and ordered alphabetically by 'descriptiu
What's the best way to select the data and render it in HTML?
I thought about going thru each element (of the whole table) at a time, and
making an array, dynamically adding bits of the tree together until the
whole tree has been grown ... but it seems a little bit complicated and slow
... is there anything that could be done [database]server-side which might
help me?
Or do other people have code snippets, ideas or anything which might help
me??
Thanks,
Siggy