$val) { // save value to "questions" array if this is a TEXT tag if ($val[tag] == "TEXT") { $questions[$questionNo]['text'] = $val[value]; } // save value to "questions" array if this is a CHOICES tag if ($val[tag] == "CHOICES") { $questions[$questionNo]['choices'] = $val[value]; } // save value to "questions" array if this is an ANSWER tag if ($val[tag] == "ANSWER") { $questions[$questionNo]['answer'] = $val[value]; // increment question counter variable $questionNo++; } } import_request_variables("p", "post_"); include($headerFile); if (!isset($post_answers)) { echo "" . $questions[0]['text'] . "\n"; echo "
\n"; // split choices into "choices" array $choices = explode(", ", $questions[0]['choices']); // print text field if there are no choices if (count($choices) == 1) { echo "\n"; } // print radio fields if there are multiple choices else { // print a radio button for each choice for ($i = 0; $i < count($choices); $i++) { echo " " . $choices[$i] . "
\n"; } } echo "\n"; echo "
\n"; } // // PRINT NEXT QUESTION // elseif (count($questions) > count($post_answers)) { // get number of next question $nextQuestion = count($post_answers); // print question echo "" . $questions[$nextQuestion]['text'] . "\n"; echo "
\n"; // print answers to previous questions as hidden form fields for ($i = 0; $i < count($post_answers); $i++) { echo "\n"; } // split choices into "choices" array $choices = explode(", ", $questions[$nextQuestion]['choices']); // print text field if there are no choices if (count($choices) == 1) { echo "\n"; } // print radio fields if there are multiple choices else { // print a radio button for each choice for ($i = 0; $i < count($choices); $i++) { echo "" . $choices[$i] . "
\n"; } } // print appropriate button label if (count($questions) == count($post_answers) + 1) { echo "\n"; } else { echo "\n"; } echo "
\n"; } // // CALCULATE AND PRINT SCORE // else { // get number of questions $noQuestions = count($questions); // get number of correct answers for ($i = 0; $i < $noQuestions; $i++) { // increment "noCorrectAnswers" variable if user has correct answer if ($questions[$i]['answer'] == $post_answers[$i]) { $noCorrectAnswers++; } } // calculate score $score = ($noCorrectAnswers / $noQuestions) * 100; // round score to nearest whole precentage point $score = round($score); // print score echo "

$score%

\n"; if ($noCorrectAnswers == 0) { echo "

You answered no questions correctly. Try again?

"; } if ($noCorrectAnswers == 1) { echo "

You answered 1 out of $noQuestions questions correctly. Try again?

"; } if ($noCorrectAnswers > 1 && $noCorrectAnswers < $noQuestions) { echo "

You answered $noCorrectAnswers out of $noQuestions questions correctly. Try again?

"; } if ($noCorrectAnswers == $noQuestions) { echo "

You answered all questions correctly!

"; } } // // INCLUDE FOOTER FILE // include($footerFile); ?>