简体   繁体   中英

It only displays one message rather choosing correct message to display

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>';
}

}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM