Warren Vail wrote:

I did one once where the key to the table was a string, and the string
contained 1 to n Node Numbers separated by a separator character.

"1"
"1.1"
"1.1.1"
"1.2"

select data from table where node between (1 and 2)

resulted in an entire limb of the tree being retrieved.  Limitations were
the size of the string, depth of the tree (the string was truncated), and
the number of digits in each node number.  Problem also with ordering node
numbers, node number 1 tended to be followed by node number 10, 11, 12, etc,
then number 2, until I pre-determined the number of leading zeros for each
node.

Not pretty, but it works well for small trees.

Warren Vail



Been there, done that, ran into the same limitations :-)

The "flat table" solution in the article suggested by Marek keeps a running "display order" integer column, updated only when items are added (or removed, but that's not strictly necessary if you don't mind holes in the sequence). When inserting a new item, it gets the display order value of the parent + 1, and the following items have their display order incremented by 1. Simple. There's also an "indentation level" column, which is simple enough to maintain.

/Mattias

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to