0
I’m creating a quiz, but how do I make sure the questions don’t repeat themselves?
// Executa uma consulta que pega as questoes
$sql = 'SELECT * FROM `questoess` WHERE IdPergunta=' .rand(1,4);
$query = $mysqli->query($sql);
while ($dados = $query->fetch_array()) {
echo ' ' . $dados['Pergunta'] . '<br><br>';
echo '<input type="radio" name="a" />'. 'AlternativaA: ' . $dados['AlternativaA'] . '<br>';
echo '<input type="radio" name="b" />'. 'AlternativaB: ' . $dados['AlternativaB'] . '<br>';
echo '<input type="radio" name="c" />'. 'AlternativaC: ' . $dados['AlternativaC'] . '<br>';
echo '<input type="radio" name="d" />'. 'AlternativaD: ' . $dados['AlternativaD'] . '<br>';
echo '<input type="radio" name="e" />'. 'AlternativaE: ' . $dados['AlternativaE'] . '<br>';
}
Welcome, you can start by doing tour and to get answers that solve your question / problem read How to ask a good question?.
– NoobSaibot
Is the idea to show all questions in random order? Is this code you put running inside a loop? For it seems to me that he selects only one question at a time and there would be no repetition.
– Woss
puts the question printing before the while, taking only the content of the first line, and then at the while you print the alternatives. It is repeating because in each row you have the alternative and the question... the question getting inside the while, will be printed as well
– Rovann Linhalis