Dynamic menu creation using php/mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swiftguy
Forum Newbie
Posts: 2
Joined: Tue Aug 29, 2006 10:04 am

Dynamic menu creation using php/mysql

Post by swiftguy »

Hello Experts,

We are developing an php/mysql application where in we are planning a menu as seen in the following website( http://www.xtrememac.com/ ).The menu options should come from the database(mysql), so basically its dynamically generated menu.. can anybody point me to any good tutorial(creating dynamically generated menu[2,3 level menus] using php/mysql]).Googled a lot but could'nt find a good howto/tutorial for this job :(

plz help me out.

Regards,
Swiftguy.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Set your database of menu items up so that each entry has link text, a link URL, an id, and a parent id. You can then recursively iterate through each row & build a multi-dimensional array out of the results. So, if an entry doesn't have a parent id set, it's at the top level. If you find a row with a parent id, put it in the appropriate top level element.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There's a post in the sticky of Client Side (I believe) that has a link to sitepoint on hierarchical menus that may be of interest.
Post Reply