以下にforeachループがあり、各テーブル行のデータが表示されます。
foreach ($studentData['questions'] as $questionId => $questionData) {
...
echo '<td width="30%" class="answers">'.htmlspecialchars($questionData['answer']).'</td>' . PHP_EOL;
...
echo '<td width="30%" class="studentanswer">'.htmlspecialchars($questionData['studentanswer']).'</td>' . PHP_EOL;
}
私がやりたいのは、studentanswer
一致するanswer
場合studentanswer
は緑色になり、一致しない場合は間違った答えを赤で表示し、完全にstudentanswer
一致する場合は100%と一致する場合は、文字列ステーションを緑色で表示answer
するなどの変数が必要です。 100%一致しない場合は、文字列を赤で表示します。$check
fully correct
not full correct
したがって、たとえば、上記のコードはこれを表示できます。
Answer: B C
Student Answer: B D
上記の出力では、解答B
と一致するため、生徒の解答は緑色で表示されますが、解答B
がないため、生徒の解答D
は赤色で表示さD
れます。生徒の答えは完全には正しくなく、部分的であるため、変数$check
は赤で表示されます。not fully correct
しかし、これはどのように達成できますか?
アップデート:
テキストの色は変わりません。
if($questionData['answer'] == $questionData['studentanswer']) {
$style = 'green';
$checked = 'Fully Correct';
} else {
$style = 'red';
$checked = 'Not Correct / Not Fully Correct';
}
echo '<td width="30%" class="answers '.$style.'">'.htmlspecialchars($questionData['answer']).'</td>' . PHP_EOL;
...
echo '<td width="30%" class="studentanswer '.$style.'">'.htmlspecialchars($questionData['studentanswer']).'</td>' . PHP_EOL;
CSS:
.red{
color: red;
}
.green{
color: green;
}