0
I’m listing some results within while my goal is that when any of the variables I list in while come empty, it lists only those that come with content.
ps. is a polling system, I put to register 4 answers, but some questions have only yes or no as answers, so I want to list only those variables that come with content, follows the code below:
<?
$consulta = "SELECT * FROM perguntas ORDER BY id ASC " ;
$resultado_consulta = mysql_query($consulta) or die("Erro no SQL: ".mysql_error());
while($lista = mysql_fetch_array($resultado_consulta)){
$id = anti_injection($lista['id']);
$validacao_campo = anti_injection($lista['$validacao_campo']);
$pergunta_principal = anti_injection($lista['$pergunta_principal']);
$primeira_opcao = anti_injection($lista['$primeira_opcao']);
$segunda_opcao = anti_injection($lista['$segunda_opcao']);
$terceira_opcao = anti_injection($lista['$terceira_opcao']);
$quarta_opcao = anti_injection($lista['$quarta_opcao']);
?>
<fieldset>
<br>
<h2 class="fs-title"> <?php echo $lista['pergunta_principal']; ?> </h2>
<br>
<h3 class="fs-subtitle"></h3>
</fieldset>
<?php
if (!empty("$lista['primeira_opcao'];")){
echo"<?php echo $lista['primeira_opcao']; ?> <input type='radio' value='<?php echo $lista['primeira_opcao']; ?>'
name='<?php echo $lista['validacao_campo']; ?>'> ";
}
if (!empty("$lista['$segunda_opcao'];")){
echo"<?php echo $lista['segunda_opcao']; ?> <input type='radio' value='<?php echo $lista['segunda_opcao']; ?>'
name='<?php echo $lista['validacao_campo']; ?>'>";
}
if (!empty("$lista['$terceira_opcao'];")){
echo"<?php echo $lista['terceira_opcao']; ?> <input type='radio' value='<?php echo $lista['terceira_opcao']; ?>'
name='<?php echo $lista['validacao_campo']; ?>'>";
}
if (!empty("$lista['$quarta_opcao'];")){
echo"<?php echo $lista['quarta_opcao']; ?> <input type='radio' value='<?php echo $lista['quarta_opcao']; ?>'
name='<?php echo $lista['validacao_campo']; ?>'>";
}
endif;
?>
<br><br>
<input type="button" name="previous" class="previous action-button" value="Anterior" />
<input type="button" name="next" class="next action-button" value="Proxima" />
</fieldset>
<?php } ?>
And the problem is which?
– rray
is giving error in showing time,
– João Lucas Chaves
I think it’s the final montage.. I’ll edit the code on the question that was wrong.
– João Lucas Chaves
What mistake is it? could you edit the question with it.
– rray
Posting a minute
– João Lucas Chaves
Where I edit my post ?
– João Lucas Chaves
Below that blue comic (php, if, while) has the edit link, so code get formatted select it and press the button
{ }
– rray
Click on [Edit]
– Jéf Bueno
edited, is better for you to see ?
– João Lucas Chaves