I have a form which contains a dropdown list of countries generated from database. The values are stored in database. There is an option in which user can view or update the valuesinserted. For updating all the form values get fetched from database. What i require is that when form is loaded for updating the selected option of the country dropdown must be that stored in the database. For eg: if from the following dropdown option2 is selected and inserted into database.
Dropdown: |option1|<selected>
|option2|
|option3|
during update it should be like this
Dropdown: |option1|
|option2|<selected>
|option3|
Here is the code i tried.
$selected = $list["country_country_name"];
<tr><td>Country</td><td><select onchange="getCountry(this.value);" name="country" id="country" ><?php foreach( $query as $qry ) {
print '<option value="'.$qry["country_country_name"].'"';
if( $qry["country_country_name"] == $selected ) print'selected';
print '>'.$qry["country_country_name"].'</option>'."\n";} ?>
</select></td></tr>