Option selected

0

I'mnewtoPHPandIneedyourhelp,I'monaformeditingscreenandI'mhavingdifficultyselectingtheselectI'vedoneinthedatabase.Thequeryreturnedas"S", but the "N" and "S" are also appearing. The correct one is to appear only the "S" which is the return of the bank and the "N", in case I wanted to change to the "N". What am I doing wrong?

I thank you for your attention.

    
asked by anonymous 07.04.2018 / 12:10

1 answer

1

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

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

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

There are ways to not have to repeat manually, so just loop the previously defined values.

    
07.04.2018 / 12:49