Page 1 of 1

[solve]dynamic values for select option

Posted: Mon Aug 08, 2005 9:50 pm
by tkarven
hi,

i got two select in my page, and i would like the second select to have it's value dynamically changed based on values for first select.

e.g. my first select is country while my second select one is state. so obviously whenever the user specify a country the second select will changed automatically.

can anyone specify a direction or keyword for me to overcome this scenario ?

thx a lot..

Posted: Mon Aug 08, 2005 9:57 pm
by John Cartwright

Code: Select all

SELECT * FROM countries 
INNER JOIN states 
USING (country_id)
WHERE countries.name = 'Canada'
This is assuming that you have a key connecting the states and the country (country_id) and your countries tables name column is `name`. To dynamically change 'Canada' change the value to $_GET['name'] and pass the value through the query string..

so countries.php?name=Canada

Code: Select all

$sql = 'SELECT * FROM countries 
INNER JOIN states 
USING (country_id)
WHERE countries.name = \''.$_GET['name'].\'';

Posted: Mon Aug 08, 2005 10:05 pm
by tkarven
hmmh, i got no prob with the database linking. my question was, how to us update the second select, whenever the user specify a country in the first select ? anyway thx for ur reply

Posted: Mon Aug 08, 2005 10:12 pm
by harrisonad
Maybe CoderBoglin will help you in his tutorial
viewtopic.php?t=29084

READ BEFORE POST

Posted: Mon Aug 08, 2005 10:13 pm
by John Cartwright

Code: Select all

$sql = 'SELECT * FROM countries
INNER JOIN states
USING (country_id)
WHERE countries.name = \''.$_GET['name'].''; 

if (isset($_GET['state'])) {
   $sql .= ' AND states.name = \''.$_GET['state'].'\'';
}
Im probably being thick, but can you rephrase your question. I don't really understand what your asking for.

Posted: Mon Aug 08, 2005 11:10 pm
by tkarven
okie viewtopic.php?t=29084 exactly wad i looking for.

thx all