N级树PHP MYSQL帮助

时间:2009-10-14 22:06:07

标签: php mysql html treenode

我一直在看N-level tree class

任何人都可以建议我可以显示结果的最佳方式,即结果集的循环,我应该使用DIV还是UL?

如果您发现文章太长而无法阅读

,示例结果集将如此
Array ( [531] => stdClass Object ( [id] => 531 [rid] => 0 [created] => 1255384549 [nleft] => 1 [nright] => 8 [nlevel] => 1 ) [534] => stdClass Object ( [id] => 534 [rid] => 531 [created] => 1255384549 [nleft] => 2 [nright] => 3 [nlevel] => 2 ) [532] => stdClass Object ( [id] => 532 [rid] => 531 [created] => 1255384587 [nleft] => 4 [nright] => 7 [nlevel] => 2 ) [533] => stdClass Object ( [id] => 533 [rid] => 532 [created] => 1255384628 [nleft] => 5 [nright] => 6 [nlevel] => 3 ) )

任何建议都是apreciated

由于

3 个答案:

答案 0 :(得分:1)

找到我正在寻找的解决方案。

        function _generateTreeData(&$arr, $id, $level, &$n)
    {
        $arr[$id]->nlevel = $level;
        $arr[$id]->nleft = $n++;

        // loop over the node's children and process their data
        // before assigning the nright value
        foreach ($arr[$id]->children as $child_id) {
            $this->_generateTreeData($arr, $child_id, $level + 1, $n);
        }
        $arr[$id]->nright = $n++;
    }

现在进入格式化

答案 1 :(得分:0)

有点取决于你需要对输出做什么。我个人会使用未排序的列表或定义列表。

你想做什么?

答案 2 :(得分:0)

将其输出为UL和LI。如果输出过于复杂,您可以在其上放置一个JavaScript“树视图”组件 - 最好是可以自动将UL转换为树视图的组件。