atw
06-10-2007, 04:30 PM
Here is my existing code: function display_children() {
$nav_menu = "<ul>\n";
$parent_result = mysql_query( "SELECT id, name FROM developments WHERE parent_id IS NULL AND visible = 'y' ORDER BY 'name' ASC;" );
while( $parent_row = mysql_fetch_assoc( $parent_result )) {
$parent_id = $parent_row['id'];
$nav_menu .= "\t<li>" . $parent_row['name'] . "\n";
$child_result = mysql_query( "SELECT id, name FROM developments WHERE parent_id = '$parent_id' AND visible = 'y' ORDER BY 'name' ASC;" );
while( $child_row = mysql_fetch_assoc( $child_result )) {
$nav_menu .= "\t\t<li>" . $child_row['name'] . "</li>\n";
}
$nav_menu .= "\t</li>\n";
}
$nav_menu .= "</ul>\n";
return $nav_menu;
}
This code generates this output:<ul>
<li>item1
<li>subitem1-1</li>
</li>
<li>item2
<li>subitem2-1</li>
<li>subitem2-2</li>
</li>
</ul>
As you can see it does work but I need to get the script to add opening and closing <ul>s around the subitems (and their respective <li>s).
Any help would be gratefully received...
$nav_menu = "<ul>\n";
$parent_result = mysql_query( "SELECT id, name FROM developments WHERE parent_id IS NULL AND visible = 'y' ORDER BY 'name' ASC;" );
while( $parent_row = mysql_fetch_assoc( $parent_result )) {
$parent_id = $parent_row['id'];
$nav_menu .= "\t<li>" . $parent_row['name'] . "\n";
$child_result = mysql_query( "SELECT id, name FROM developments WHERE parent_id = '$parent_id' AND visible = 'y' ORDER BY 'name' ASC;" );
while( $child_row = mysql_fetch_assoc( $child_result )) {
$nav_menu .= "\t\t<li>" . $child_row['name'] . "</li>\n";
}
$nav_menu .= "\t</li>\n";
}
$nav_menu .= "</ul>\n";
return $nav_menu;
}
This code generates this output:<ul>
<li>item1
<li>subitem1-1</li>
</li>
<li>item2
<li>subitem2-1</li>
<li>subitem2-2</li>
</li>
</ul>
As you can see it does work but I need to get the script to add opening and closing <ul>s around the subitems (and their respective <li>s).
Any help would be gratefully received...