How do I create nav menu for a cms?

倖福魔咒の 提交于 2019-12-13 17:29:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!