Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to create a dynamic menu from DB?

 
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.
 
Ranch Hand
Posts: 334
2
Netbeans IDE Tomcat Server Java
  • 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
 
Paper beats rock. Scissors beats tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic