查询COUNT个回显

查询COUNT个回显

问题描述:

I have an error in counting and echoing the the answer. BTW i am Making an examination system where in I am counting how many students answer a , b ,c d

try to understand my program. I am not good in English

<?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"];


                                }
                ?>

Here I am just counting How many student who answered optiona.

Try this,

$info = mysql_fetch_object($data);
echo $info->total_count;