Help making a multiple choice quiz with jFormer (jQuery and PHP)
I was wondering if anyone could help me out with a multiple choice quiz I'm making with jFormer.
Basically I'm really new to PHP and I'm having trouble with the following:
- Finding out how to arrange radio buttons vertically (at the moment I'm basing my quiz on the 'Survey' Demo (http://www.jformer.com/demos/survey/) and it won't let me rearrange the radio buttons. Instead, when I do, it treats each开发者_JS百科 radio button separately and you can only pick the first one.
- All my radio buttons are labeled A - E (e.g.
< input id="statement1-choice3" type="radio" value="C" name="statement1" / >
) How do I then calculate the outcome so that those who picked a majority of A answers get shown a different div to those who picked a majority of B answers?
Thanks in advance,
Ella
To calculate the outcome, you'll probably have all the answers in a list (array).
In your case the array variable would be $_POST
I think...
So when you have an array with answers:
$data = array(
'question1' => 'a',
'question2' => 'b',
'question3' => 'a',
'question4' => 'c',
'question5' => 'a',
'question6' => 'e',
'question7' => 'c',
'question8' => 'd',
'question9' => 'a',
'question10' => 'a',
'question11' => 'b'
);
You can go through each answer of the array and look which answer there has been given. Then count each answer and look of which are the most.
$a = 0;
$b = 0;
$c = 0;
$d = 0;
$e = 0;
foreach($data as $question => $answer) {
if($answer == 'a') {
$a++;
} else if($answer == 'b') {
$b++;
} else if($answer == 'c') {
$c++;
} else if($answer == 'd') {
$d++;
} else if($answer == 'e') {
$e++;
}
}
if($a > $b && $a > $c && $a > $d && $a > e) {
echo '<div>Most of your answers where A</div>';
} else if($b > $c && $b > $d && $b > $e) {
echo '<div>Most of your answers where B</div>';
} else if($c > $d && $c > $e) {
echo '<div>Most of your answers where C</div>';
} else if($d > $e) {
echo '<div>Most of your answers where D</div>';
} else {
echo '<div>Most of your answers where E</div>';
}
Since your still beginning with PHP I'd make the code so clear as possible. There are many (more difficult and not easy understandable) ways to do this.
精彩评论