Selected option

Asked

Viewed 32 times

0

inserir a descrição da imagem aqui

Guys, I’m new to PHP and I need your help, I’m on a form editing screen and I’m having a hard time selecting the select I made in the database. The query returned as "S", but the "N" and "S" are also appearing. The correct is to show only the "S" which is the return of the bank and the "N", in case I wanted to change to the "N". What I’m doing wrong?

I thank you for your attention.

1 answer

1


If this is binary (S/N) and the received value is between the two, then you could use the selected, to select an existing value.

<option value="S" <?= $dado['enc'] == 'S' ? 'selected' : '' ?>>S</option>
<option value="N" <?= $dado['enc'] == 'N' ? 'selected' : '' ?>>N</option>

That way if the value is S he will select the S existing. What you are doing is to include a new option, so you can duplicate an existing one.

There are ways of not having to repeat manually, so just make a loop with the values previously defined.

  • That’s right, I did and it worked, thank you.

Browser other questions tagged

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