我有一個問題從表'問題'中選擇問題,隨機化它,只選擇15個問題。我想出了下面的查詢,這不是我希望的。隨機,查詢,限制
$singleSQL = mysql_query("SELECT * FROM questions WHERE id='$question' ORDER BY RAND() LIMIT 1");
while($row = mysql_fetch_array($singleSQL))
{
$id = $row['id'];
$thisQuestion = $row['question'];
$type = $row['type'];
$question_id = $row['question_id'];
$q = '<h2>'.$thisQuestion.'</h2>';
$sql2 = mysql_query("SELECT * FROM answers WHERE question_id='$question' ORDER BY rand()");
while($row2 = mysql_fetch_array($sql2))
{
$answer = $row2['answer'];
$correct = $row2['correct'];
$answers .= '<label style="cursor:pointer;"><input type="radio" name="rads" value="'.$correct.'">'.$answer.'</label>
<input type="hidden" id="qid" value="'.$id.'" name="qid"><br /><br />
';
}
$output = ''.$q.','.$answers.',<span id="btnSpan"><button onclick="post_answer()">Submit</button></span>';
echo $output;
}
}
,如果你有連基本的錯誤處理,你會被告知關於你的第一個查詢中的語法錯誤。永遠不要成功。總是檢查錯誤:'mysql_query(...)或die(mysql_error());' –
'ORDER BY'在WHERE子句之後,而不是之前。 RT * M http://dev.mysql.com/doc/refman/5.7/en/select.html –
感謝您的關注,先生,看來我在輸入查詢時犯了一個粗心的錯誤,它會盡量避免它下次。 – user3286777