我一直在看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 ) )


任何建议都很赞赏

谢谢

最佳答案

找到了我想要的解决方案。

        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++;
    }


现在进入格式化

关于php - N级树PHP MYSQL HELP,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1569283/

10-09 19:55