我已经知道如何随机进行 Mysql/php 查询, 但我如何追踪已经询问过的问题却不再被拉动。 使用大小写: 测试有10个问题。 问题需要随机顺序。 我如何追踪问题( rows) 2, 5,6, 8, 9 已经回答过, 问题1, 34, 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);
提前感谢!