Re: Associated popup menu (php/mysql)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Let's see if I'm understanding you correctly. You want to have a form with 
2 or more popup menus, where a choice of `country` in the first menu then 
populates a second popup menu with the `states` located in that country? 

If this is what you're asking, I do this all the time using select (or 
drop down) boxes in html (with PHP, JavaScript, and a MySQL back-end). 
Perhaps it can be used also for pop-ups...?

The basics are to have the form submit to itself, have the database query 
selecting all `countries` populate the first menu when the page is first 
displayed by running a "select id_country, country from Countries" query 
against your database, then use the id_country of the selected country to 
run a second query, "select state_names from states where id_country = 
{$_POST['value_returned_from_first_query']}". I usually use 
'onchange=\"this.form.submit()\"' to automate the submittal of the 
form/page.
 
Use conditional statements in your PHP code to control which queries get 
run, that is, only run the second query if the variable for the selected 
country has a value in it.

The PHP manual has lots of examples about how to use built-in functions 
for a variety of databases to query and retrieve data.

HTH,

dave


>Hello all,
>
>I've been searching for hours and cannot find the answer or sample in in 
any
>forum.
>
>What is the best method (any sample or help would be appreciated), to
>associate popup menus in a form. Choosing the first popup menu (Main
>categorie) should provide to me the results for the second popup menu
>(subcategory).
>
>Ie : Countries --> states
>
>I know that javascript can do this sort of things, but I would like to 
use
>only php. Is that possible ?
>
>I have two tables in mysql: Countries & states that can be associated by
>id_country.

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux