1 回答

TA貢獻1775條經驗 獲得超11個贊
基本上,我們使用 2 個SELECT語句并將UNION它們組合成一個結果集。
SELECT question, type, Topic, Skill, imagename, answerA, answerB, answerC, answerD, correctanswer FROM goodquestions WHERE type = 'mathnocalc' ORDER BY RAND() LIMIT 0,10
上面的查詢將返回 10 個 mathnocalc 類型的隨機行。您一定會確信這一點。我將上述查詢用作與另一個查詢的 UNION 的嵌套查詢。
SELECT * FROM (SELECT question, type, Topic, Skill, imagename, answerA, answerB, answerC, answerD, correctanswer FROM goodquestions WHERE type = 'mathnocalc' ORDER BY RAND() LIMIT 0,10) as cat1
UNION
SELECT * FROM (SELECT question, type, Topic, Skill, imagename, answerA, answerB, answerC, answerD, correctanswer FROM goodquestions WHERE type = 'mathcalc' ORDER BY RAND() LIMIT 0,10) as cat2
嘗試上面的查詢并讓我知道結果。
要根據類別顯示結果,您可以簡單地將查詢分為兩部分:
邏輯示例:
$queryNoCalc = 'SELECT question, type, Topic, Skill, imagename, answerA, answerB, answerC, answerD, correctanswer FROM goodquestions WHERE type = 'mathnocalc' ORDER BY RAND() LIMIT 0,10';
$noCalcResult variable will store the result set of above query.
Similarly,
$queryCalc = 'SELECT question, type, Topic, Skill, imagename, answerA, answerB, answerC, answerD, correctanswer FROM goodquestions WHERE type = 'mathcalc' ORDER BY RAND() LIMIT 0,10';
$calcResult variable will store the result set of above query.
現在,您可以在不同的 DIV 中使用單獨的結果。
<div class="no-calc">
<h3>NO CALULATOR ALLOWED</h3>
while ($noCalcResult):
Do the stuff;
endwhile;
</div>
<div class="calc">
<h3>CALULATOR ALLOWED</h3>
while ($queryCalc):
Do the stuff;
endwhile;
</div>
希望你能理解這個概念。
- 1 回答
- 0 關注
- 137 瀏覽
添加回答
舉報