File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes PHP and the fly likes How to create a dynamic menu from DB? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » PHP
Bookmark "How to create a dynamic menu from DB?" Watch "How to create a dynamic menu from DB?" New topic
Author

How to create a dynamic menu from DB?

Mradul Jain
Greenhorn

Joined: Feb 22, 2010
Posts: 2
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.


My (extension) name is exe and I am not a VIRUS
Joe Areeda
Ranch Hand

Joined: Apr 15, 2011
Posts: 294
    
    2

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


It's not what your program can do, it's what your users do with the program.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create a dynamic menu from DB?
 
Similar Threads
Enable/Disable editing of Tree Node
Vertucal Menu bar based on database values
onLoad in DispatchAction
populating the data from array list
Need an idea on Navigation link selection color