• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to create a dynamic menu from DB?

Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Ranch Hand
Posts: 334
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic