Hi,
It looks like you need a recursive function. This function below does what you need, but then for a nested menu structure.
Hope you get the logic behind it..
J.
$menuquery = "select * from $menu_table order by M_sortorder";
$result=mysql_query($menuquery) or die('An error occured retrieving data');
$listing = Array();
while($row = mysql_fetch_array($result))
{
$listing["$row[M_page_nr]"] = array("This_id" => $row[M_page_nr],
"parent_id" => $row[M_p_nr],
"category_title" => $row[M_label],
"link" => $row['M_link']);
}
function display_tree($parent, $level, $array, $arr)
{
foreach ($array AS $node)
{
if($node[parent_id] == $parent) //The parent of page in array matches current parent
{ // and this page is a child of the parent
$indent1 = "";
$indent2 = "";
for($i = 0; $i <= $level; $i++)
{
$indent1 .= " ";
$indent2 .= "-";
}
$oneup = $level+1;
$html .= "
$indent1 <input name=\"editable\" type=\"radio\" value=\"$node[This_id]\">$indent2 $node[category_title]<br>
";
$html .= display_tree($node[This_id], $oneup, $array, $arr); // find more children of parent
}
}
return $html;
} // end function display list
// Now use it
$pageslist = display_tree($startlevel, 0, $listing, $arr);