Bring in select html the record that was saved in the database

Asked

Viewed 30 times

-1

Good morning Can anyone tell me how to bring into a Select component of html the records that are in PHP ? In fact, I know how to bring, but how can I bring only what was saved in the bank and even select others. Below is the code as I am doing. I need to bring the doctor who was registered but at the same time select other if I wish to change...

inserir a descrição da imagem aqui

  • what is displayed on the screen as it is now?

  • He’s bringing all the records...

  • Of course he has to bring everyone, but he does not bring selected what is saved in the bank..

  • that $tb_medico_id_medico["tb_medico_id_medico"] would be that this saved in the bank?

  • Yes, it is the one saved in the bank...tb_medico_id_medico is the table field

  • Please click on [Edit] and put the code as text. Putting it as an image is not ideal, understand the reasons reading the FAQ.

  • Possible duplicate of Bring data in Select with PHP

Show 2 more comments

1 answer

0


You can do it this way, where it checks the id and if it matches he displays a selected:

<?php

if(count($resultMedicoAll))
{
    foreach($resultMedicoAll as $res) { ?>
        <option value="<?=$res["id_medico"]?>" <?=($tb_medico_id_medico["tb_medico_id_medico"] == $res["id_medico"] ? "selected" : '')?>> <?=$res["nm_medico"]?> </option> 
<?php }
}

?>
  • I did the code Voce posted, but it didn’t work...

  • Oops, sorry it worked, yeah. I forgot to refresh the page... Thanks...

Browser other questions tagged

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