我已经知道如何进行随机 mysql/php 查询,但是如何跟踪已经查询过的内容不会再次被拉出。用例:一个有 10 个问题的测验。这些问题需要按随机顺序排列。如何跟踪问题(行)2、5、6、8、9 已经回答,但问题 1、3、4、7、10 仍然存在。这是我到目前为止所拥有的:
$current_test = $_SESSION['testid'];
// v v v query for this TEST
$tests = mysql_query("SELECT * FROM the_tests WHERE the_tests.testid=$current_test");
$test = mysql_fetch_array($tests);
// ^ ^ ^ query for this TEST
// v v v query for the QUESTIONS from this Test
// Generate
if ($test['randomize']==1){
$offset_result = mysql_query("SELECT FLOOR(RAND() * COUNT(*)) AS offset FROM the_questions WHERE the_questions.test_id_q=$current_test");//SELECT FLOOR(RAND() * COUNT(*)) AS offset FROM the_questions WHERE `qid` NOT IN (1,5,6) AND the_questions.test_id_q=1
$offset_row = mysql_fetch_object($offset_result);
$offset = $offset_row->offset;
$questions = mysql_query("SELECT * FROM the_questions WHERE the_questions.test_id_q=$current_test LIMIT $offset, 1 " );
}else{
$questions = mysql_query("SELECT * FROM the_questions WHERE the_questions.test_id_q=$current_test");
}
$totalQuestions = mysql_query("SELECT * FROM the_questions WHERE the_questions.test_id_q=$current_test");
$totalQs = mysql_num_rows($totalQuestions);
$testQ = mysql_fetch_array($questions);
提前致谢!