php和mysql查询返回值

时间:2014-06-17 07:11:56

标签: php mysql

function test_score($test_id,$page,$user_id)
{

GLOBAL $con;
$count=0;
$query=mysqli_query($con,"SELECT user_id, test_id, 
SUM(status='correct')  AS correct_answers, 
SUM(status='incorrect') AS incorrect_answers
FROM (SELECT qa.question_id, qa.test_id, uta.user_answer,uta.user_id,  qa.type,
qa.answers correct_answer,
CASE WHEN uta.user_answer = qa.answers THEN 'correct' ELSE 'incorrect' END
AS status
FROM questions_answer qa
LEFT JOIN 
(
SELECT user_id, type, test_id, question_id,
GROUP_CONCAT(answers ORDER BY answers) AS user_answer,
timestamp from user_test_answers
WHERE  test_id = '$test_id'    
GROUP BY user_id, question_id

) uta
ON qa.question_id = uta.question_id 
where qa.test_id=1 AS results
GROUP BY user_id, test_id
ORDER BY user_id, test_id ");

while($result=mysqli_fetch_assoc($query))
{
$answer_correct=$result['results'];
if($answer_correct=="correct")
{
$count++;
}
}

返回$ count;}

$ count返回什么值...我希望使用上述查询中的正确答案中的值获取top3得分者的值...如何从正确答案字段中获取最大值以及计算正确答案的数量到b存储在database..plz help..i我无法理解这段代码

0 个答案:

没有答案