I need to leave the selected option selected according to the field recorded in mysql. The form is to edit pos so it displays the available fields with the foreach.
Ex:
<select name="segurado" >
<option value=""></option>
<?php foreach ($result as $rs) { ?>
<option value="<?php echo $rs["nome"]; ?>"><?php echo $rs["nome"]; ?></option>
<?php } ?>
</select>
In this way select shows the insured table fields but I want to leave the selected record field for selected edit.
Maybe I did not make myself understood correctly: I retrieve the field saved in mysql and I can put it in the select label but this is not the solution. But this shows that the variable to compare is correct, ie the one recorded in the table when registering. Since I want to edit the registry, I need this saved and saved field to be set to selected in options, which in turn is being fed by foreach and creating the elements in the same way as in the registry. Here is the example of how to fill in the option:
$sql = "SELECT * FROM seguradoras ORDER BY nome";
try {
$stmt = $DB->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll();
} catch (Exception $ex) {
echo($ex->getMessage());
}
With it populated, I want it to show the variable that comes from the bank in the case $ residential-> insurance
Improved people?