我有一张桌子question_attempts
。此表格包含两列rightanswers
和youranswer
。
我想获得记录数rightanswer
= youranswer
。这实际上是我的整个代码。
$quizsections = mysql_query("SELECT * FROM quiz_sections");
while($quizsectionsrslt = mysql_fetch_array($quizsections)){
$quizsectionsid = $quizsectionsrslt['id'];
$quizsectionsheading = $quizsectionsrslt['heading'];
$quizsectionsquizid = $quizsectionsrslt['quizid'];
$quizsectionsfirstslot = $quizsectionsrslt['firstslot'];
echo $quizsectionsheading."<br />";
$quizslots = mysql_query("SELECT * FROM quiz_slots WHERE `quizid`=$quizsectionsquizid LIMIT ".($quizsectionsfirstslot-1).", 10");
while($quizslotsrslt = mysql_fetch_array($quizslots)){
$quizslotids = $quizslotsrslt['questionid'];
$questions = mysql_query("SELECT * FROM question_attempts WHERE `questionid`=$quizslotids");
$num_rows = mysql_num_rows($quizslots);
while($answercount = mysql_fetch_array($questions)){
$answercountrslt = $answercount['questionid'];
echo $rightanswer = $answercount['rightanswer'];
echo $youranser = $answercount['responsesummary']."<br />";
//Here want to display the count of rightanswer and count of wrong answer.
}
}
echo "Total Questions : ".$num_rows."<br /><br />";
}
答案 0 :(得分:3)
使用下方:
[[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelInfo];
答案 1 :(得分:1)
如果你只想获得计数,那么你可以使用mysql_num_rows
$questions = mysql_query("SELECT count(*) FROM question_attempts where rightanswers=youranswer");
$count=mysql_num_rows($questions);
答案 2 :(得分:1)
您可以通过SQL查询执行任务,并执行正确答案的内容
$questions = mysql_query("SELECT * FROM question_attempts where rightanswers=youranswer");
$count = mysql_num_rows($questions);
// $count is number of right answers
while($row = mysql_fetch_array($questions))
{
// Stuff on right answers
}