I’ll try to explain this the best I can.
I have a drop down populated with country names from one table. When someone selects say Canada, I need a second dropdown to filter the results from a second table called regions.
Here is the code I’m using
<?php
$query="SELECT * FROM location_region";
$result = mysql_query ($query);
echo "<select id='province_select' name='province_select' class='province_select' style='width:540px' value=''></option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[value]>$nt[name]</option>"
}
echo "</select>";
?>
I know I have to change the Query, but can I do something like:
$query="SELECT * FROM location_region WHERE country EQUALS value FROM location_country";
This doesn’t work, but is there another where of writing this? The table
“location_region” has a column named “country” that should be equal to the column “value” from the table “location_country”
Thanks as always
EDIT: For Gershon Herczeg here is the table structure
location_country is something similar to:
ID name value
1 Canada CA
2 Great Britain GB
3 United States US
location_region is similar to:
ID name value country
1 Alberta AB CA
2 Alabama AL US
3 British Columbia BC CA
Yes, this is called an inner join – it’ll effectively give you one big collection of rows matched on a column or columns specified.
Replacing in the selected value into the query, this should give you everything from the regions table for the country you’ve selected.
However, if you have a country column in the regions table which matches values in your dropdown, why don’t you just select from that to begin with?