问题
I'm creating a cms, I want to produce a set of unordered lists for a nav drop down menu. First, I select all of the menus and links from the database, then I want them to be outputed as unordered lists using php (including the 'main' list's 'child' list if there is one) How do I do it?
Main list-> <li><a href="#">Products</a>
<ul>
Child list-> <li><a href="#">Foo</a></li>
</ul>
</li>
回答1:
The result you get from database is stored as an array, you can do a foreach loop and iterate over the database result and do like this:
<li><a href="#">Products</a>
<?php
foreach($rows as $value)
{
//these are the child list items you got from database
echo "<ul><li><a href="#">".$value."</a></li></ul>";
}
?>
</li>
来源:https://stackoverflow.com/questions/9410990/how-do-i-create-nav-menu-for-a-cms