它只显示一条消息,而不是选择要显示的正确消息

时间:2013-03-08 05:57:27

标签: php

我正在尝试确定正确回答的问题,并且问题回答错误。如果回答正确则显示“完全正确”否则如果不正确则显示“不正确”消息。问题是否正确无论是否始终显示问题的答案都不正确。

以下是代码:

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

}

1 个答案:

答案 0 :(得分:1)

此行后再次设为true <{1}}。$check

if($questionData['answer'] == $questionData['studentanswer'])
{
echo '<td width="30%" class="studentanswer green"><strong>'.htmlspecialchars($questionData['studentanswer']).'</strong></td>' . PHP_EOL;
$check = true;
} else