I love programming, programming is my friend ... :-\
Mapping is tricky stuff -- at least for my brain.
Here I've made a multidimensional array of your menu hierarchy from your database results...
Of course then you have to write it to your table-menu structure -- but first things first.
<?php
$rows[] = array( 2, 'News', 0 );
$rows[] = array( 3, 'Service', 0 );
$rows[] = array( 4, 'Terms', 3 );
$rows[] = array( 5, 'Recent', 2 );
$rows[] = array( 6, 'Policy', 4 );
$rows[] = array( 7, 'Downloads', 0 );
$rows[] = array( 8, 'Links', 0 );
$rows[] = array( 9, 'Tech', 8 );
// Equivelant to: while ( $row = mysql_fetch_row( $result ) )
$i = 0;
while( $row = $rows[$i] ) {
$mapped[$row[0]] = array( label => $row[1], child => array() );
$source[$row[2]] = $row[0];
$i ++;
}
krsort( $source );
foreach ( $source as $pid => $id ) {
if ( $pid && array_key_exists( $pid, $mapped ) ) {
$values = $mapped[$id];
unset( $mapped[$id] );
$mapped[$pid]['child'][] = $values;
}
}
print_r( $mapped );
?>
Hope this helps you get started anyway
...