Bring selected based on database values

2

Ihaveanemployeeregistrationscreen,whenIeditapersonIcannotgetsettheoptionthatisregisteredinthebank.

obs.theoptionscomefromthebankandnotfromthehtmlform.

ForexampleIhaveapersonwhoisregisteredas"sales" plus when I edit it list as "accounting" which would be the first record of my local table.

code:

 <tr>
      <td align="right"><label for="txtColaborador_local">Local:&nbsp</label></td>
      <td align="left">
      <select class="form-control" name="local_id" required="required" value="<?php echo $row['local']; ?>">
      <?php while($local = mysql_fetch_array($query_local)) { ?>
      <option value="<?php echo $local['local_id'] ?>"><?php echo $local['nome'] ?></option>
      <?php } ?>
      </select> 
      </td>
   </tr>
    
asked by anonymous 18.06.2016 / 00:17

1 answer

1

Do you want to bring selected the option that is registered?

And what table is registered? but for what I understood, the logic would be for you to do something like this:

    <option <?php if($dadosEdit[$campo[$n]]==$opcao[0]){ echo "selected";} ?> 
value="<?php echo $opcao[0] ?>"><?php echo $opcao[1]; ?></option>
    
18.06.2016 / 02:24