I've made a simple PHP based exam for my students. The results are recorded as "q1", "q2", "q3", "q4" and "q5" in the database.
Correct answers are recorded as "yes" and incorrect answers as "no".
There are 5 questions and I want the total score to be 100.
All the functions work as I'd like them to, but the problem is, I have no idea how to sort the results from high to low. Any help is highly appreciated!
$result = mysqli_query($db,"SELECT * FROM table");
while($row = mysqli_fetch_array($result)){
$score = 0;
echo '<img alt="'.$row["name"].'" src="images/'.$row["name"].'.jpg" width="118" height="158"';
if ($row["q1"] === "yes") {$score=$score+20;}
if ($row["q2"] === "yes") {$score=$score+20;}
if ($row["q3"] === "yes") {$score=$score+20;}
if ($row["q4"] === "yes") {$score=$score+20;}
if ($row["q5"] === "yes") {$score=$score+20;}
echo ' /> '.$row["name"] . ' ' . $score;
}