Hi I have a piece of php code which takes php variables from a database and then populates A drop down box. This works fine but once the page updates it doesn't display the selected value and instead just displays the original list again.
I have played around with some different ideas of using isset to displays the selected value, but then it just displays that value and nothing else.
I have attached the original code where it works but always only shows the original list of values from the database.
If any body could provide a solution or even a nudge in the right direction then it would be much appreciated.
Thanks
if (isset($select) && $select != "location") {
$select = $_POST['location'];
}
?>
<select name="location">
<?php
// Get records from database (table "name_list").
$list = mysql_query("select DISTINCT region_name from masterip_details WHERE country_code='GB' AND TRIM(IFNULL(region_name,'')) <> '' order by region_name asc");
// Show records by while loop.
while ($row_list = mysql_fetch_assoc($list)) {
$location = $_POST['location']; ?>
<option value="<?php echo $row_list['region_name']; ?>"
<?php if $row_list['region_name'] == $select) {
echo "selected";
} ?>><?php echo $row_list['region_name']; ?></option>
<?php } ?>