It is a class that calls iteself however many times it needs to. Here is the code I have used, hopefully, reading it will put you on the right track, its probably a bit more complicated than you need because it is dealing with restricted menu items but you should get the idea from it.
Let me know how you get on.
<?php
class shownav {
var $curlevel;
function disp($level,$navarray,$db,$indent,$sess){
// get the access groups
$accessarray=explode(",",$sess->accessgroup);
$this->curlevel=$level;
// get the menu items for this level
if($items=$db->get_results("SELECT id, title, calledfrom, displaypos, page, accessgroup FROM navigation WHERE calledfrom='$this->curlevel' AND demo<='$sess->demo' ORDER BY displaypos")){
foreach($items as $item){
// check this is not a restricted item
if($item->accessgroup==0 OR in_array($item->accessgroup,$accessarray)){
//and if not display it
echo "<tr><td NOWRAP>";
if($indent>0){
//indent this menu item if necessary
for($f=0;$f<$indent;$f++){
echo "<img src=\"images/spacer.png\">";
}
}
// update our session variables ready for the link
$sess->page=$item->page;
$sess->nav=$item->id;
$sess->updatesess();
echo "<a href=\"goto.php?sess=$sess->sess\" title=\"$item->title\"";
//if we are shwoing a restricted item change its colour
if($item->accessgroup!=0 AND $item->id!=$sess->curnav) echo " style=color:#FF0000; ";
//if we are shwoing the current menu item change its colour
if($item->id==$sess->curnav) echo " style=color:#000000; ";
echo ">$item->title";
echo "</a></td></tr>";
if(in_array($item->id,$navarray)){
// if this is in our list of display levels display it
$newset=new shownav;
$newset->disp($item->id,$navarray,$db,$indent+1,$sess);
}
}
}
}
}
}
$curlevel=0;
// create array for each sublevel back to 0 so we know which sub menue to show
$navarry=array();
$curlevel=$sess->nav;
while($curlevel!=0){
$navarray[]=$curlevel;
// get the previous level
$curlevel=$db->get_var("SELECT calledfrom FROM navigation WHERE id='$curlevel'");
}
?>
<table cellpadding=0 cellspacing=0>
<?php
//start at level 0
$navarray[]=0;
$newset=new shownav;
// show the menu
$newset->disp(0,$navarray,$db,0,$sess);
?>
</table>
Phodetheus