Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Selecting using MYSQL

looking for help in selecting directory levels



11:33 pm on Jun 20, 2008 (gmt 0)

10+ Year Member


Wondering if anyone can help me here - I use Linux, HTML, PHP and MYSQL in my sites, but unfortunately have a very limited knowledge of javascript.

I have a directory which for example has a top level of:
England, Scotland, Ireland and Wales

Under ALL of those, a sub level of:
Widgets1, Widgets2, Widgets3 etc...

Then, under all of those

Product1, Product2, Product3 etc...

and possibly another level.

I need a javascript program which will access the MYSQL database to present a popup to allow users to select, say 'England'. When they select that, the sublevel will allow them to select a Widget, then once they have done that, can select the Product option.
I then need to get the selected option back into the database/html/php or whatever?

Appreciate this is probably simple stuff, but its just not my area.

Anyony suggest any urls I can look at, or (ideally) code they can post or sticky me with?

IF this can't be done in javascript - any ideas?

Thanks very much.


12:06 am on Jun 21, 2008 (gmt 0)

5+ Year Member

I'm no expert on this myself, but I don't think JavaScript needs to be used here. I don't think it even can be used (to access a database).

I would do away with the directory method and have the page be a PHP full of if-else statements.

URL structure:

The code would resemble:

IF (the country variable isset in the URL) {
IF (the widget isset in the URL) {
IF (the product isset in the URL) {
display info about the product;
offer a choice of product;
offer a choice of widget;
offer a choice of country;

This way, no worries about client javascript support, no annoying pop-ups, and it's bookmarkable because of the URL query string.

I hope I understood you. If this is misleading or confusing, please post or pm me.


9:43 am on Jun 21, 2008 (gmt 0)

10+ Year Member

Thanks for the reply febfoo.

I could use something like that (in fact I do).

But what I mean is if the user is on a page, I have a button which says 'choose a new category'

Clicking that displays a javascript (or some other language if it needs to) popup, so the user does not have to leave the current page, that allows choice of top level category.
They choose one and unerneith allows choice of a sub category, choosing that then allows a choice of the bottom level categories (all selected from my MYSQL database).

Clicking OK returns to the html/php page where their choices are now inserted into the screen when the user can select 'GO' and it will take them there.

Any ideas?


4:51 pm on Jun 21, 2008 (gmt 0)

5+ Year Member

I still like avoiding pop-ups. Just have a part of the page be a div that is hidden/showed by javascript.

That div could contain a PHP-generated javascript. Using PHP, select the categories from the database. Have the PHP write a some kind of javacript offering the choices from the database. My mind is going blank about how exactly to do this, but I'm sure you can figure it out.



8:04 pm on Jun 21, 2008 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Any ideas?

When outputting the page, use your PHP to generate your subcategories and lists, and in doing so output the Javascript dynamically and store those lists in Javascript arrays. So when the page loads, you'll have all the elements you need to modify the lists. I don't have any code but it would be something like

<select name="country" onChange="createWidgetList()">

Where createWidgetList uses document.createElement to create the widget list and write it to the page. The widget list would use the same method to create a product list onChange. This of course becomes problematic on extremely long lists.

Doing it this way, you could test for Javascript and if it's not enabled, add a "next" button to submit each select list to the script and regenerate the page using the methods mentioned in the previous post. Best of both worlds, this makes it non-Javascript dependent.

Learn how here [w3schools.com]


8:35 pm on Jun 21, 2008 (gmt 0)

10+ Year Member

Some good ideas here, thanks for all the advice, very useful, I'm sure I can work with these.

Thanks again, and appologies for the typo on your name Webfoo!



2:13 pm on Jun 22, 2008 (gmt 0)

5+ Year Member

Not sure if this is what you're looking for but you could populate a list via Ajax. You would need PHP or another database-able coding package to use it though...Good luck!

Featured Threads

Hot Threads This Week

Hot Threads This Month