The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

function display_memu($root=0){// retrieve the left and right value of the $root node $result=mysql_query('SELECT lft, rgt FROM categories '.'WHERE parent_id="'.$root.'";');$row=mysql_fetch_array($result,MYSQL_ASSOC);// start with an empty $right stack $right=array();$left=array();// now, retrieve all descendants of the $root node $result=mysql_query('SELECT ctitle, lft, rgt FROM categories '.'WHERE lft BETWEEN '.$row['lft'].' AND '.$row['rgt'].' ORDER BY lft ASC;');// display each row while($row=mysql_fetch_array($result)){// only check stack if there is one and get rid of rootif(count($right)>0){// check if we should remove a node from the stack while($right[count($right)-1]<$row['rgt']){$rows=array_pop($right);var_dump($rows);}$parentRight=$right[count($right)-1];$parentLeft=$left[count($left)-1];$change=($row['lft']==($parentRight+2))?'T':'F';$isChild=(($row['lft']-$parentLeft)==1)?'T':'F';$sibling=(!($row['rgt']-$row['lft']-1)&&(($row['lft']-$parentLeft)==2)) ?'T':'F';$descendants=($row['rgt']-$row['lft']-1)/2;/*
echo $row['ctitle']."<br>";
echo 'descendants '.$descendants."<br>";
echo 'change '.$change."<br>";
echo 'sibling '.$sibling."<br>";
echo 'ischild '.$isChild."<br>";
echo "-----------------------------<br>";
*///echo "<pre>";//var_dump($right);// display indented node title }// add this node to the stack $right[]=$row['rgt'];$left[]=$row['lft'];}}

It doesn't work yet
but it can be at least a start point
(just a rough past and copy)

Code PHP:

function display_memu($root=0){// retrieve the left and right value of the $root node $result=mysql_query('SELECT lft, rgt FROM categories '.'WHERE parent_id="'.$root.'";');if(!$result){die('Invalid query: '.mysql_error());}$row=mysql_fetch_array($result,MYSQL_ASSOC);// start with an empty $right stack $right=array();// now, retrieve all descendants of the $root node $result=mysql_query('SELECT id,ctitle, lft, rgt FROM categories '.'WHERE lft BETWEEN '.$row['lft'].' AND '.$row['rgt'].' ORDER BY lft ASC;');$right=array();// Stack of right values $currentLevel=1;$lastLevel=1;$menu='<ul class="categories-tree">'."\n";// display each row while($row=mysql_fetch_array($result)){// only check stack if there is one if(count($right)>0){// check if we should remove a node from the stack while($right[count($right)-1]<$row['rgt']){array_pop($right);}$lastLevel=$currentLevel;$currentLevel=count($right);if($currentLevel<$lastLevel){for($i=0;$i<$lastLevel-$currentLevel;$i++){$menu.='</ul></li>'."\n";}}$menu.='<li><a href="'.$row['id'].'">'.$row['ctitle'].'</a><li>';if($row['rgt']-$row['lft']>1){$menu.='<ul>'."\n";}else{$menu.='</li>'."\n";}}$right[]=$row['rgt'];}// Close remaining unordered lists for($i=0;$i<$currentLevel-1;$i++){$menu.='</ul></li>'."\n";}return$menu;}

publicfunction fetchMenu($root=0){if($root==0){$root=$this->getRootId();if($root===false){returnnull;}}$categories=$this->getDescendantsRows($root);if(count($categories)===0){returnnull;}$tab=' ';// For proper XHTML indentation $right=array();// Stack of right values $currentLevel=1;$lastLevel=1;echo$tab,$tab,$tab,'<ul class="categories">',"\n";foreach($categoriesas$category){if(count($right)>0){// Check if we should remove a node from the stack while($right[count($right)-1]<$category->rgt){array_pop($right);}$lastLevel=$currentLevel;$currentLevel=count($right);//If we have moved to upper level, close opened unordered lists if($currentLevel<$lastLevel){for($i=0;$i<$lastLevel-$currentLevel;$i++){echostr_repeat($tab,$lastLevel-$i+2),'</ul></li>',"\n";}}// Add this node to the unordered list echostr_repeat($tab,$currentLevel+3),'<li>',$category->ctitle;if($category->rgt-$category->lft>1){echo'<ul>',"\n";}else{echo'</li>',"\n";}}// Add this node to the stack $right[]=$category->rgt;}// Close remaining unordered lists for($i=0;$i<$currentLevel-1;$i++){echostr_repeat($tab,$currentLevel-$i+2),'</ul></li>',"\n";}echo$tab,$tab,$tab,'</ul>',"\n";}