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

Recommended Answers

All 5 Replies

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.

Member Avatar for diafol

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.

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 :)

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.