i use this peace of code for print out tree list (structure: id, parent, name):
obj(id=>, parent=>, name=>,)
<!-- The HTML for the tree-->
<ul id="designtree">
<?
$ch=array(); //for started top nodes
foreach ($list as $lst) {
if($lst->type == 'spacer'){$lst->title = "<hr>";}
if ($lst->parent == 0 && $lst->children == 0) {
print("<li><a href=\"$lst->url\">$lst->title</a></li> \n");
}
if ($lst->children != 0 && ($lst->parent == 0 || (isset($ch[$lst->parent]) && $ch[$lst->parent] >= 1 ))) {
$ch[$lst->id]=$lst->children;
if ($lst->parent != 0 && isset($ch[$lst->parent]) && $ch[$lst->parent] >= 1) {
$ch[$lst->parent] = $ch[$lst->parent]-1;
}
print("<li><a href=\"$lst->url\">$lst->title</a><ul> \n");
}
if ($lst->children == 0 && isset($ch[$lst->parent]) && $ch[$lst->parent] >= 1 ){
print("<li><a href=\"$lst->url\">$lst->title</a></li> \n");
$ch[$lst->parent] = $ch[$lst->parent]-1;
}
if($ch[$lst->parent] == 0 && isset($ch[$lst->parent])) {
print("</ul></li>");
}
}
print("</ul></li></ul> \n");
evrything ok, if i just whant to print out tree. but i need to put nodes to <ul><li></li></ul>
exmpl:
<ul>
<li>node1</li>
<li>node2
<ul>
<li>node2.1</li>
</ul>
</li>
</ul>
and so on.
but i have problem when node reached node2.1.1
it close parent node 2.1 before puting items in it.
any sugestions?
p.s. sorry fo english