I need to create a simulation that will do a SELECT of 5 questions at random.
I'm using ORDER BY RAND()
, but the results repeat, and I do not know how I can fix it.
I even created a vector that stores the code for each question, but I do not know how to compare it at the time of SELECT
.
Does anyone know how I can fix this problem?
The code:
$con = conectar();
$x=1;
for($i=$x; $i<=$x+4; $i++){
$sql = "SELECT * FROM simulado where cod_disc like 1 order by RAND()";
$res = mysqlexecuta($con,$sql);
$row = mysql_fetch_array($res);
echo $i . ") " . $row['enunciado'];
$questoes[$i] = $row ['cod_questao'];
}
* The mysqlexecuta method just runs the query and checks for any runtime errors.