Connecting Tech Pros Worldwide Help | Site Map

Place drop down menu selection into a variable to be used in an sql query

Newbie
 
Join Date: Mar 2007
Posts: 1
#1: Mar 17 '07
Hi There,

I am a bit of a newbie to PHP programming and I would like to know how I can place a selected drop down option into a PHP variable and then produce an sql query which incorporates this variable.

I have created a dynamic drop down menu that populates itself with data from a MySQL table. I now want it to populate a second drop-down menu with relevant options from my database, based upon a query using a variable.

For example.....

I.e. drop-down one options = Fruit
Vegetables

The user selects Fruit.

drop-down two options = Apple
Pear
Banana
Orange
etc...

In this way, only options relevant to the first drop-down selection are shown in the second drop-down.

Can you help, please.

Regards,

Chris.
ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,439
#2: Mar 17 '07

re: Place drop down menu selection into a variable to be used in an sql query


The best way to do this PHP/AJAX. As you mentioned in your post you have already completed the first List menu. So for the onchange event of those list items, you have to call for a JS function, to submit the Values to the server side script.
from there generate the Next List menu and Print it back in the same page.

Other way is using a $PHP_SELF action form.
Don't ask to submit the coding for these stuffs. start it by your self and if error occurs come back to the thread with your Codings. :)
Newbie
 
Join Date: Mar 2007
Posts: 5
#3: Mar 27 '07

re: Place drop down menu selection into a variable to be used in an sql query


Hello not sure about PHP but for javascript you can just use the onchange and then put this.value and then call a function to save the value
Reply