Bring Selected based on database values

Asked

Viewed 904 times

2

inserir a descrição da imagem aqui

I have an employee registration screen, when I edit a person I can not bring set the option that is registered there in the bank.

Obs. options come from the database and not from the html form.

for example I have a person who is registered as "sales" more when I edit her 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>

1 answer

1


You want to bring selected the option that is registered?

And which table is registered this? us more information about the table... But from what I understood, the logic would be 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.