tree structure class

From: Date: Thu, 11 Oct 2001 16:13:56 +0000
Subject: tree structure class
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-2250@lists.php.net to get a copy of this message
is there some class which represents a tree structure in php, that is saved in the db? if not i have written one which, if interested, i would like to commit to pear so here is what i have * this class can be used to step through a tree using [parent], [child], etc. * the tree is saved as flat data in a db, where at least the parent * needs to be given if a previous member is given too then the order * on a level can be determined too * actually this class was used for a navigation tree * now it is extended to serve any kind of tree * you can unambigiously refer to any element by using the following * syntax * tree->data[currentId][<where>]...[<where>] * <where> can be either "parent", "child", "next" or "previous", this way * you can "walk" from any point to any other point in the tree * by using <where> in any order you want * example (in parentheses the id): * root * +---level 1_1 (1) * | +----level 2_1 (2) * | +----level 2_2 (3) * | +-----level 3_1 (4) * +---level 1_2 (5) * * the database table to this structure (without defined order) * id parentId name * 1 0 level 1_1 * 2 1 level 2_1 * 3 1 level 2_1 * 4 3 level 3_1 * 5 0 level 1_2 * besides those fields in the db you can save any other additional * column too * * now you can refer to elements for example like this (all examples assume you know the starting element): * to go from "level 3_1" to "level 1_1": $tree->data[4][parent][parent] * to go from "level 3_1" to "level 1_2": $tree->data[4][parent][parent][next] * to go from "level 2_1" to "level 3_1": $tree->data[2][next][child] * to go from "level 2_2" to "level 2_1": $tree->data[3][previous] * to go from "level 1_2" to "level 3_1": $tree->data[5][previous][child][next][child] i am still working on performance optimization tell me if interested for pear this class can be used for any tree-stuff, like dynamic menus or whatever ... Wolfram

« previous php.pear.dev (#2250) next »