Reputation: 307
I am trying to determine questions answered correctly and questions answered incorrectly. If answered correctly then display "Fully Correct" else if incorrect then display the "Incorrect" message. Problem is no matter if correct or not it always displays that question is answered incorrectly.
Below is code:
$check = true;
foreach ($studentData['questions'] as $questionId => $questionData) {
if($questionData['answer'] == $questionData['studentanswer'])
{
echo '<td width="30%" class="studentanswer green"><strong>'.htmlspecialchars($questionData['studentanswer']).'</strong></td>' . PHP_EOL;
}
else
{
echo '<td width="30%" class="studentanswer red"><strong>'.htmlspecialchars($questionData['studentanswer']).'</strong></td>' . PHP_EOL;
$check = false;
}
if($check)
{
echo '<p class="green"><strong>Fully Correct</strong></p>';
}
else
{
echo '<p class="red"><strong>Not Correct / Not Fully Correct</strong></p>';
}
}
Upvotes: 1
Views: 29
Reputation: 30488
after this line again set to true
for $check
if($questionData['answer'] == $questionData['studentanswer'])
{
echo '<td width="30%" class="studentanswer green"><strong>'.htmlspecialchars($questionData['studentanswer']).'</strong></td>' . PHP_EOL;
$check = true;
} else
Upvotes: 1