Consider the following structure:
A table named "Regions" with the columns "id","name".
A table named "Cities" with the columns "id","region_id","name".
What is the best way to repopulate an html select options using PHP and Javascript?
For example lets say I have the following php code:
<select name = "region">
<option value = "">Select Region</option>
<?
foreach ($regions as $region)
{
echo "<option value = '$region[id]'>region[name]</option>";
}
?>
</select>
<select name = "city">
<option value = "">Select City</option>
</select>
Once a region has been selected, all the cities with the proper foreign key "region_id" that corresponds to the selected region, will be populated into the cities select.
Assume that I use this kind of structure a lot, so I do want to have a minimal, easy to reuse code.