02-27-2008, 11:32 AM
|
#3 (permalink)
|
|
The Contributor
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
|
Basicly you select all the items from your menu table, and then let php work it out.
Hope it helpes.
PHP Code:
<?php
/// Select from the table
/// Delimiters if parent = 0 = main. if parent != 0 sub child of
while ( $r = mysql_fetch_array( $result) ) {
if ( $r['parent'] == 0) {
$parent[$r['id']] = $r;
} else {
$parent[$r['parent']]['subpage'][] = $r;
}
}
// So you will have thin in your array
/*
[1] => array( 'id' => '1',
'name' => 'Main',
'subpage' => array ( [0] => array( 'id' => '3',
'name' => 'Main Sub Page 1'
),
[1] => array( 'id' => 12,
'name' => 'Main Sub Page 2'
)
)
),
[2] .....
*/
foreach ( $parent as $id => $data ) {
echo $data['name'];
echo "br";
$subpage = $data['subpage'];
if ( is_array( $subpage) ) {
foreach ( $subpage as $_i => $sub ) {
echo $sub['name'];
echo "br";
}
}
}
/* OUTPUT ----
Main
--- Main SubPage 1
--- Main SubPage 2
Menu Item 2
Menu Item 3
... Menu Item 3 SubPage 1
... Menu Item 3 SubPage 2
*/
?>
__________________
Back from sysadmins to the programmers.
|
|
|