An option would also test the value for each option
and print selected
when matching, eg:
<label>Tipo Beneficiario: </label> <span> <?php echo $TipoBeneficiario; ?></span>
<div class="">
<select name="tipoBeneficiario">
<option value="0" <?=($TipoBeneficiario == 'Selecione')?'selected':''?> >Selecione</option>
<option value="1" <?=($TipoBeneficiario == 'Conjugue')?'selected':''?> >Conjugue</option>
<option value="2" <?=($TipoBeneficiario == 'Filho')?'selected':''?> >Filho</option>
<option value="3" <?=($TipoBeneficiario == 'Mãe/Pai')? 'selected':''?> >Mãe/Pai</option>
<option value="4" <?=($TipoBeneficiario == 'Companheira(o)')?'selected':''?> >Compannheira(o)</option>
</select>
</div>
In the example, the condition is tested using if ternary , where
<?=($TipoBeneficiario == 'Companheira(o)')? 'selected' : ''?>
is the same as
<?php
if($TipoBeneficiario == 'Companheira(o)'){
echo 'selected';
}
?>
If you do not have the option of short tags enabled on the server or prefer not to use, you can do:
<label>Tipo Beneficiario: </label> <span> <?php echo $TipoBeneficiario; ?></span>
<div class="">
<select name="tipoBeneficiario">
<option value="0" <?php echo $TipoBeneficiario=='Selecione'?'selected':'';?> >Selecione</option>
<option value="1" <?php echo $TipoBeneficiario=='Conjugue'?'selected':'';?> >Conjugue</option>
<option value="2" <?php echo $TipoBeneficiario=='Filho'?'selected':'';?> >Filho</option>
<option value="3" <?php echo $TipoBeneficiario=='Mãe/Pai'?'selected':'';?> >Mãe/Pai</option>
<option value="4" <?php echo $TipoBeneficiario=='Companheira(o)'?'selected':'';?> >Companheira(o)</option>
</select>
</div>