tags:

views:

96

answers:

4

What is the best 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?

A: 

You might wanna check this question: http://stackoverflow.com/questions/1620505/generating-many-nested-lists-using-php-and-mysql - I suspect that you are the author of both :)

phidah
No I'm not the author of both, but I will check out the article though.
php
Does not explain the PHP issue though.
php
+1  A: 

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.

Adrian
A: 

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.

Michael
A: 

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.

Don