Last active
December 31, 2015 12:29
-
-
Save johnsardine/7986358 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$score = array(); | |
$negative_score = array(); | |
$answers = ( !empty($_POST['answers']) ) ? $_POST['answers'] : array(); | |
foreach ( $answers as $question_id => $answer ) { | |
// here you will make a query with the $question_id and compare the database answer with the variable $answer provided by the uder | |
$answer_is_true = true; // here you would make a verification that would return either true or false | |
// if answer is true | |
if ( $answer_is_true ) { | |
$score[] = 1; // 1 being the score attributed to this question | |
} else { | |
$negative_score[] = 1; | |
} | |
} | |
$score_total = array_sum($score); // sum of the scores | |
$negative_score_total = array_sum($negative_score); // sum of the scores | |
// you now have positive score and negative scroe, you just need to subtract the negative score to the total score, like 30 - 20 = 10 score | |
var_dump($score_total); | |
?> | |
<form method="POST"> | |
<p>Question 1</p> | |
<label> | |
<input type="radio" name="answers[1]" value="a" /> | |
Answer A | |
</label> | |
<label> | |
<input type="radio" name="answers[1]" value="b" /> | |
Answer B | |
</label> | |
<p>Question 2</p> | |
<label> | |
<input type="radio" name="answers[2]" value="a" /> | |
Answer A | |
</label> | |
<label> | |
<input type="radio" name="answers[2]" value="b" /> | |
Answer B | |
</label> | |
<p><button type="submit">Submit</button></p> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment