0
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++;
}
}

return $count;}

what value does $count return..i want to get the value of top3 scorers using value in correct answers from above query...how to get maximum value out of correct answers field as well as count the no of correct answers to b stored in database..plz help..i am not able to understand this code

NRJ
  • 13
  • 3
  • is that a typo? your `mysqli_query()` is missing a `;` – user1978142 Jun 17 '14 at 07:14
  • yes forgot to enter here – NRJ Jun 17 '14 at 07:16
  • and plus put `error_reporting(E_ALL); ini_set('display_errors', '1');` on top of your php so that you could see the errors – user1978142 Jun 17 '14 at 07:18
  • i am getting scream.. and this error: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www – NRJ Jun 17 '14 at 07:22
  • most likely a series/chain of events. `$query` is false that is why `mysqli_fetch_assoc()` gave an error. then, it means there is an error on the query statement – user1978142 Jun 17 '14 at 07:23
  • if i run the sql it show results perfectly in the form of variables correct answers/incorrect answers/userid.. i want to know how to fetch these values...from'results' or from'correct_answers' – NRJ Jun 17 '14 at 07:43
  • why duplicate i want to know the result of query.....?? – NRJ Jun 17 '14 at 08:46
  • maybe you could check the link that was given, i have no power to close this question – user1978142 Jun 17 '14 at 09:02

0 Answers0