PHP ver gevorderde |
|
Dit zou moeten werken voor wat jij wilt. ;)
Natuurlijk moet je nog wel de tabel naam in de query aanpassen.
<?php
if(($rResult = mysql_query('SELECT * FROM table')) !== false && mysql_num_rows($rResult) > 0)
{
function submenu($iCurrent, $aRows, $iLayer = 0)
{
foreach ($aRows as $iKey => $aRow)
{
if ($aRow['parent_id'] == $iCurrent)
{
print str_repeat('- ', $iLayer).$aRow['title'].'<br />';
unset($aRows[$iKey]);
if ($aRow['isagroup'])
{
submenu($aRow['id'], $aRows, $iLayer + 1);
}
}
}
return true;
}
$aRows = array();
while (($aRow = mysql_fetch_assoc($rResult)) !== false)
{
$aRows[] = $aRow;
}
submenu(0, $aRows);
}
?>
<?php { function submenu($iCurrent, $aRows, $iLayer = 0) { foreach ($aRows as $iKey => $aRow) { if ($aRow['parent_id'] == $iCurrent) { if ($aRow['isagroup']) { submenu($aRow['id'], $aRows, $iLayer + 1); } } } return true; } { $aRows[] = $aRow; } submenu(0, $aRows); } ?>
|