$content = ' "info": {
"name": "Think You Know Baseball ",
"main": "
Think you\'re smart enough to be on Jeopardy? Find out with this super crazy knowledge quiz!
",
"results": "Learn More
",
"level1": "Jeopardy Ready",
"level2": "Jeopardy Contender",
"level3": "Jeopardy Amateur",
"level4": "Jeopardy Newb",
"level5": "Stay in school, kid..." // no comma here
},
"questions": [ ';
$dbh = new PDO("mysql:host=localhost;dbname=mmaaaco_ksecor","mmaaaco_ksecor","hamilton");
$sql = $dbh->prepare("select questionid, question from 3312questions order by rand()");
$sql->execute();
while ($row = $sql->fetch()){
$qid = $row[0];
$question = $row[1];
$content .= ' {
"q": "'.$question.'",'."";
//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'].' and you can learn more from mm214.com'; //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": ['."";
foreach ($possibleanswers as $indanswer){
if ($answer == $indanswer) $mark = 'true';
else $mark = 'false';
$content .= '{"option": "'.$indanswer.'", "correct":'.$mark.'},'."";
}
$content .= ' ],""
"correct": "That\'s right! !
",
"incorrect": "Uhh no.'.$description.'
"
},';
}
echo $content;
?>