3个表quiz_sections
,quiz_attempts
和question_attempts
表格的列如下图所示。
$USER->id
是当前登录的用户ID变量。
这是我的代码
<?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'];
}
}
}
我得到的输出
我想分割userid=3
性向
1 2 3 4 ... 10
算术
11 12 13 ... 20
推理
21 22 23 ... 30
计算机
31 32 33 ... 40
userid=4
的结果为41到80。
这些是表结构。
答案 0 :(得分:1)
您需要在thr $quizsectionsfirstslot
查询中使用question_attempts
:
$questionattempts = mysql_query("SELECT * FROM question_attempts
WHERE `questionusageid`=$quizattemptsids
AND slot BETWEEN $quizsectionsfirstslot AND $quizsectionsfirstslot + 9");