3 tables quiz_sections
, quiz_attempts
and question_attempts
tables having their columns as shown below attached screenshot.
$USER->id
is the current logged in user id variable.
Here is my code
<?php
echo "Current User ID : ".$USER->id."<br />";
$quizsections = mysql_query("SELECT * FROM quiz_sections");
while($quizsectionsrslt = mysql_fetch_array($quizsections)){
echo $quizsectionsheading = $quizsectionsrslt['heading']."<br />";
$quizsectionsquizid = $quizsectionsrslt['quizid'];
$quizsectionsfirstslot = $quizsectionsrslt['firstslot'];
$quizattempts = mysql_query("SELECT * FROM quiz_attempts WHERE `quiz`=$quizsectionsquizid AND `userid`=$USER->id");
while($quizattemptsrslt = mysql_fetch_array($quizattempts)){
$quizattemptsids = $quizattemptsrslt['id'];
$quizattemptsattempt = $quizattemptsrslt['attempt'];
$quizattemptsquiz = $quizattemptsrslt['quiz'];
$questionattempts = mysql_query("SELECT * FROM question_attempts WHERE `questionusageid`=$quizattemptsids");
while($questionattemptsrslt = mysql_fetch_array($questionattempts)){
echo $questionattemptsid = $questionattemptsrslt['id'];
}
}
}
The output i got
i want to split the result for userid=3
Aptitude
1 2 3 4...10
Arithmetic
11 12 13 ...20
Reasoning
21 22 23 ...30
Computers
31 32 33 ...40
And result for userid=4
from 41 to 80.
These are the tables structure.
You need to use $quizsectionsfirstslot
in thr question_attempts
query:
$questionattempts = mysql_query("SELECT * FROM question_attempts
WHERE `questionusageid`=$quizattemptsids
AND slot BETWEEN $quizsectionsfirstslot AND $quizsectionsfirstslot + 9");