3
echo '<option value="0" {if/else} >Em revisão</option>';
echo '<option value="1" {if/else} >Publicado</option>';
I wish I had a condition if/else
to ask the database the value and give a selected
value returned. You can help me?
It would be something like: if($resultado['status'] == 1) { echo 'selected=selected'; }
can give more details?
– durtto
I believe your logic is right. Only the Selected=Selected should be, in the final string, like this: Selected="Selected". Just add the quotes. Or if it’s Html5, only
selected
resolves– celsomtrindade
The problem is that I insert {if/Else} into the echo and it misses. I’m having trouble passing the right instruction inside the echo.
– Marcos Vinicius
Look at this example: echo '<option value="'. $value. '". if($value=='United States') echo 'Selected="Selected"';. '>'. $value. '</option>';
– durtto
You can do the following: echo '<option value="0" ' . ($result['status'] == 1) ? 'Selected=Selected' '. ' >Under revision</option>'; echo '<option value="1" ' . ($result['status'] == 1) ? 'Selected=Selected' '' . ' >Published</option>';
– thalissonestrela
Jesus seems like such a simple thing ... if I put pure html I can open the tags PHP but inside the echo I can’t.
– Marcos Vinicius
That there is inside a foreach?
– rray
You are not being clear. There is a lack of information.
– durtto