我是 PHP 新手,我需要一些帮助。我似乎无法为学生获得正确的分数。
场景:
- 输入对应分数的考试答案(答案键)
- 输入该考试的学生答案
- 获取学生的总分。
我的PHP代码:
for ($count = 1; $count <= $num_ans; $count++)
{
$answer = $_POST['answer'][($count + 1) - 1];
$sqlB = "SELECT * FROM paper WHERE id=$count and test_name = '$test_name' and subject='$subject'";
$qryB = mysql_query($sqlB);
$rowB = mysql_fetch_array($qryB);
$anskey = $rowB['answer'];
}
if ($answer = $anskey)
{
$sqlA = "SELECT points FROM paper WHERE test_name = '$test_name' and subject='$subject' and answer='$answer'";
$qryA = mysql_query($sqlA);
while ($rowA = mysql_fetch_array($qryA))
{
$correctAns += $rowA['points'];
}
}