I have a foreach loop which shows a option list with all the countries in it
foreach($countries as $cc => $name) {
echo '<option value="' . $name . '">' . $name . '</option>';
}
The selected option gets saved in the database. What i want to do is that if I go back to this page that it showed the already selected option from the database. How would I do this?
Thanks.
just put the selected attribute on the one which you want to select
Try this:
Retrieve the country id and store it in a variable
Select box
The below code displays all the options of country array. $cc will check with the database value ($selectedOption) and that country will get selected by default.
Or when you create your select object
Sorry was just quickly typing it in wasnt going for syntax just the method
should be the proper syntax