I have a DB with 100 questions and multiple answers for it. I wanted to display in a quiz format selecting 20 random questions at a time. I have done something like this below
$m=new MongoClient();
$db=$m->mydb;
$c=$db->quiz;
$cursor = $c->find()
$n = 20;
foreach ($cursor as $obj) {
$links=array('$obj["question"]<br><br>
<input type="radio" name="q1" value="$obj["ch1"]"> $obj["ch1"]<br>
<input type="radio" name="q1" value="$obj["ch2"]"> $obj["ch2"]<br>
<input type="radio" name="q1" value="$obj[ch3"]"> $obj["ch3"]</p>');
$rand_keys = array_rand($links, $n);
echo "<center>". "<br><table><tr><td>";
echo "1. ". $links[$rand_keys[0]] . "<br>";
echo "</td></tr><tr><td>";
echo "2. ".$links[$rand_keys[1]] . "<br>";
echo "</td></tr><tr><td>";
echo "3. ". $links[$rand_keys[2]] . "<br>";
echo "</td></tr><tr><td>";
}
It is not working. Is there anything wrong with th code? Please help me either finding the wrong to make it work or any method that would achieve my purpose.