Re: Pear::Tree - Questions and feature requests

From: Date: Sat, 26 Jul 2003 18:14:12 +0000
Subject: Re: Pear::Tree - Questions and feature requests
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-18750@lists.php.net to get a copy of this message
Simon H wrote:
Is it possible to remove the [parent] bit and only have [children] display its children and their children etc, building a
simple nested
tree from the top down only, instead of walking up and down through the whole tree for each child node? Maybe I'm still missing something?
Actually there are no copies. All the elements in there are only references, so the array is really only as big as the sum of all elements! does that answer it all?
Not really...getting confused now...LOL. Ok, what I'm trying to do is display the data from tree in a structured fashion. I'm using smarty and have tried doing some of the logic there (would prefer to if possible, at least display logic), but I'm just getting lost trying different arrays, transformations, whatever and I still cant get a basic: <ul>
    <li>
        [id] => 2
        [parentId] => 1
        <ul>
            <li>
                [id] => 3
                [parentId] => 2
                <ul>
                    <li>
                        [id] => 4
                        [parentId] => 3
                        <ul>
                            <li>
                                [id] => 9
                                [parentId] => 4
                            </li>
                            <li>
                                [id] => 8
                                [parentId] => 4
                            </li>
                        </ul>
                    </li>
                    <li>
                        [id] => 6
                        [parentId] => 3
                    </li>
                    <li>
                        [id] => 7
                        [parentId] => 3
                    </li>
                </ul>
            </li>
            <li>
                [id] => 5
                [parentId] => 2
            </li>
        </ul>
    </li>
</ul> ...type layout...indented child under parent. Its been doing my head in now for over a week. If you've any suggestions (already trying smarty boards too with little success), they'd be much appreciated. <ul> are used here in the example, but may not be the final display method.
building this tree is really simple when you use the memory way. simply call $treeNodes = $tree->getNode(); that puts a one dimensional array in $treeNodes, which is sorted as the tree is, and since every element contains a element 'level' you know how deep to indent one item, i.e. like this: foreach ($treeNodes as $aNode) { for ($i=0;$i<$aNode['level'];$i++) { print "&nbsp;"; } print $aNode['name'].'<br>'; } and the tree is printed out as it is. was that what you meant? -- Wolfram http://opensource.visionp.de ... authentication system .... http://sf.net/projects/auth

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