Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Writing a Quiz HELP

$
0
0

Hey Everyone,

I'm trying to make a quiz in PHP for a class. THis is what I have so far. I just can't get the answers to show up. Any help will be wonderful!

 

 

<?php
 
 
$quiz_questions = array();
$quiz_questions['q1'] = array(
'question' => 'What is Rebel Wilsons Character Name?',
'choices' => array(
'a' => 'Fat Amy',
'b' => 'Rebelicious',
'c' => 'Fat Samy',
'd' => 'Pitch Slapper'),
'answer' => 'a');
$quiz_questions['q2'] = array(
'question' => 'What are Nodes?',
'choices' => array(
'a' => 'An STD',
'b' => 'Vocal cords rubbing together at an above average rate w/o proper lubrication',
'c' => 'A point at which lines or pathways intersect',
'd' => 'A high note'),
'answer' => 'b');
$quiz_questions['q3'] = array(
'question' => 'What song did Beca audition with?',
'choices' => array(
'a' => 'Cups',
'b' => 'Call me Maybe',
'c' => 'Titanium',
'd' => 'No Diggity'),
'answer' => 'a');
$quiz_questions['q4'] = array(
'question' => 'Where does Beca work?',
'choices' => array(
'a' => 'Jamba Juice',
'b' => 'Vocal coach at the university',
'c' => 'University radio station',
'd' => 'McDonalds'),
'answer' => 'c');
$quiz_questions['q5'] = array(
'question' => 'What happened at last years finals?',
'choices' => array(
'a' => 'They Won',
'b' => 'Chloe had surgery on her vocal chords',
'c' => 'Bumper sabotaged the Barden Belles',
'd' => 'Aubrey threw up on stage'),
'answer' => 'd');
 
 
 
 
 
 
if($user_answers[$qid] ==' '){
//user did not answer the question
}elseif($user_answers[$qid] == $question['answer']){
//answer is correct
$total_answered++;
$total_correct++;
}else{
//answer is wrong
$total_answered++;
}
 
 
foreach($quiz_questions as $qid => $question){
//output the question text
echo '<p>'.$question['question']. '<p>';
}
 
 
foreach($question['choices'] as $cid => $choice){
 
$lid = $qid.'_'.$cid;
//default message
$msg = ' ';
 
 
$checked = ($user_answers[$qid]== $cid) ? ' checked ' : ' ';
 
 
//if all questions have been answered, display correct and wrong answers
if($total_answered > 0 and $total_answered == $total_questions){
if ($checked){
if($user_answers[$qid]== $question['answer']){
$msg = echo '<p>CORRECT!</p>';
}else{
$msg = echo '<p>INCORRECT</p>';
}
}
}
 
echo '
<input type="radio" name=" ' . $qid . ' " value= " ' .$cid. ' " id= " ' .$lid. ' " ' . $checked . '/>
<label for =" '. $lid . ' ">' . $choice . '</label>';
 
 
?>

Viewing all articles
Browse latest Browse all 13200

Trending Articles