0

Do you know how to store multi-level menus in db and build them into html lists using php?

thnx

p.s.: i googled and could not find what i need

3
Contributors
5
Replies
8
Views
6 Years
Discussion Span
Last Post by Acute
0

I don't know if you will find this all packaged together. CMS's generally have dynamic menus and individual templates may have multi-level drop-down's built on top of that. If you do a search, you will find many JQuery drop-down menu solutions. If you do a search, you can also find articles about building dynamic menus. This is one example.

0

You can use a few different patterns. The most popular would be the parent_id field, where top level items have a parent_id of 0, all sub items have a parent_id equal to the id of their parent:

id | label | url | pos | parent_id

I recently gave an answer for this. Search DW. However, I think it was for just one sublevel. Multiple levels will require something else possibly.

0

Thank you, chrishea. Well, I'm interested not in JS, but in PHP + MySQL implementation. How to store and how to build it - that's what I want to know. Actually I have one idea:
Store the items in table with below structure:
| category_id | parent_category_id | category_name |
, and build from this table the html ul li lists recursively or using two or three loops. However, it's gonna do it everytime page is loaded, so is it practically good solution?
Isn't it better to make fixed menu (because I'm writing site for myself, not CMS)?
But anyway I want to learn how professionals would make php+mysql dynamic menu :)

0

Thanks, ardav. So what is the best php solution of building nested list from the table you suggested?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.