Large dynamic side-nav menus using PHP and MySQL?
What is the b开发者_如何学JAVAest way to display a large tree side-nav menu with many nested list levels using PHP and MySQL?
How many tables should I use and how should I code the PHP?
Here is a very good article written by Gijs Van Tulder Storing Hierarchical Data in a Database
Whether you want to build your own forum, publish the messages from a mailing list on your Website, or write your own cms: there will be a moment that you'll want to store hierarchical data in a database. And, unless you're using a XML-like database, tables aren't hierarchical; they're just a flat list. You'll have to find a way to translate the hierarchy in a flat file.
You might wanna check this question: Generating many nested lists using PHP and MySQL? - I suspect that you are the author of both :)
You might also want to take a look at my nested set article: http://www.fliquidstudios.com/2008/12/23/nested-set-in-mysql/
You really don't need to do anything special on the PHP side of things because all the grunt work is done in MySQL.
table Menu (id, parent_menu_id, item_id, menu_text);
table Item (id, item_text, ...);
write your own loop to descend through the menu hierarchy starting where parent_menu_id is null.
精彩评论