Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create a dynamic menu from DB?

 
Mradul Jain
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am creating an online products catalog. In this I want to create a menu that is loaded dynamically. The menu consists of categories that may have sub-categories and leaf nodes are the products.

There is a table called categories having 3 fields catId, title, and parentCatId(Id of the parent category).
On the page, I am able to display all the top level categories. Now, what I want to do is- when a user clicks on a category(or a subcategory), it should expand and show the subcategories(if applicable) and products(leaf nodes). When a user clicks on a leaf node, it should go to page, say, product.php and the page should know what link was clicked.

How can I incorporate the above functionality? Should I use javascript for the same?

Thanks in advance.
 
Joe Areeda
Ranch Hand
Posts: 331
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Creating menu's dynamically is pretty straight forward.

Html doesn't have cascading menus, that's usually done with multiple menus. (you've seen them as a product menu then when you select that you get a model and when you select that you get a version menu)

The argument for Javascript and especially Ajax is responsiveness. The argument against is complexity.

If you're going to do php only the process would be set one menu item then hit next then php redraws the page and on and on.

With Ajax you select a menu item then javascript queries a php script and builds the next menu. So only one click on the menu instead of 2. Much better user experience.

From your question, I would suggest using the php only method for Version 1, it is MUCH MUCH simpler.

Once you get the hang of Ajax it's pretty cool and I don't want to discourage you at all from using it. it does take some time to learn to use effectively.

Joe
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic