prepare("select questionid, question from 3312questions order by rand()"); $sql->execute(); while ($row = $sql->fetch()){ $qid = $row[0]; $question = $row[1]; $content .= ' { "q": "'.$question.'",'."\n"; //call the correct answer $csql = $dbh->prepare("select answer from 3312canswer where questionid = ?"); $csql ->bindValue(1,$qid); //makes the variable safe above $csql->execute(); //executes it $crow = $csql->fetch();//grabs the resource and puts it into $row $answer = $crow['answer'];//assigns the correct answer to a usable variable for display! $possibleanswers = array();//put in array for shuffling! $possibleanswers[] .= $answer; $wsql = $dbh->prepare("select answer,description from 3312wanswers where questionid = ?"); //get the wrong answers! $wsql ->bindValue(1,$qid);//makes the variable safe above $wsql->execute(); //executes it while ($wrow = $wsql->fetch()){ $possibleanswers[] .= $wrow['answer']; $description= $wrow['description']; //add to the array on each turn of the loop for each wrong answer no limits...as fast as array_push } shuffle($possibleanswers); $content .= '"a": ['."\n"; foreach ($possibleanswers as $indanswer){ if ($answer == $indanswer) $mark = 'true'; else $mark = 'false'; $content .= '{"option": "'.$indanswer.'", "correct":'.$mark.'},'."\n"; } $content .= ' ],'."\n".' "correct": "

That\'s right! !

", "incorrect": "

Uhh no.'.$description.'

" },'; } echo $content; ?> ] };