i'm trying to get a group of random rows without repeat any of a BBDD, at the end, the code gies me the questions... but with some errors.... could anyone help me? P.D. the error is in the bolded line. (Undefined offset (in each iteration)) Thanks in advance
mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT * FROM Questions");
$num_rows = mysql_num_rows($sql);
$max_value = (int )$num_rows;
$ids[] = array(5);
for ($i = 0; $i < 5; $i++) {
$repetido = true;
while($repetido == true){
$repetido = false;
$quest_id = rand ( 1, $max_value);//Obtiene el aleatorio
for ($j = 0; $j < count($ids); $j++) {
**if ($quest_id == $ids[$i]) $repetido = true;**
}
}
$ids[$i] = $quest_id;
$sql=mysql_query("SELECT * FROM Questions WHERE id_quest = $quest_id");
$row = mysql_fetch_array($sql);
$output[$i]=$row;
}
echo(json_encode($output));
mysql_close();