0

I have been looking at a N-level tree class.

Could anyone possibly advise on the best way I could display the results ie, the looping of the result set, should I use DIVs or ULs?

An example result set will look like so if you find the article too long to read

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 ) )

Any advice is apreciated

Thanks

3 Answers 3

1

Found the solution I was looking for.

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

Now onto the formatting

Sign up to request clarification or add additional context in comments.

Comments

0

Kinda depends on what you would need to do with the output. I would personally use unsorted lists or definition lists.

What are you trying to do?

Comments

0

Output it as ULs and LIs. If the output is too complex, you can put a JavaScript "Tree view" component on top of it - preferably one that can turn a UL into a tree view automatically.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.