我在计算和回应答案时遇到错误。顺便说一下,我正在建立一个考试系统,我在计算有多少学生回答a,b,c d
尝试了解我的计划。我英语不好
<?php
while ($r = mysql_fetch_array($result)) {
$i = $i + 1;
if ($i % 2 == 0)
echo "<tr class=\"alt\">";
else
echo "<tr>";
echo "<td style=\"text-align:center;\">". $i
. "</td><td>" . htmlspecialchars_decode($r['question'],ENT_QUOTES) . "</td><td>" . htmlspecialchars_decode($r[htmlspecialchars_decode($r['correctanswer'],ENT_QUOTES)],ENT_QUOTES) . "</td><td>" . htmlspecialchars_decode($r['marks'],ENT_QUOTES) . "</td>"
. "</td></tr>";
/*
$query3 = "Select qnid, COUNT(stdnswer) AS ans1 FROM studentquestion WHERE stdanswer = 'optiona' and qnid ='" . $i ."'";
$query4 = "Select qnid, COUNT(stdnswer) FROM studentquestion WHERE stdanswer = 'optionb' and qnid ='" . $i ."'";
$query5 = "Select qnid, COUNT(stdnswer) FROM studentquestion WHERE stdanswer = 'optionc' and qnid ='" . $i ."'";
$query6 = "Select qnid, COUNT(stdnswer) FROM studentquestion WHERE stdanswer = 'optiond' and qnid ='" . $i ."'";
*/
$data = mysql_query("Select qnid, COUNT(stdnswer) AS total FROM studentquestion WHERE stdanswer = 'optiona' and qnid ='" . $i ."'");
$info = mysql_fetch_assoc($data);
echo $info["total"];
}
?>
我只是在计算有多少学生回答了选项。
答案 0 :(得分:0)
试试这个,
$info = mysql_fetch_object($data);
echo $info->total_count;