1 回答

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超11個(gè)贊
基本上,我們使用 2 個(gè)SELECT語(yǔ)句并將UNION它們組合成一個(gè)結(jié)果集。
SELECT question, type, Topic, Skill, imagename, answerA, answerB, answerC, answerD, correctanswer FROM goodquestions WHERE type = 'mathnocalc' ORDER BY RAND() LIMIT 0,10
上面的查詢將返回 10 個(gè) mathnocalc 類型的隨機(jī)行。您一定會(huì)確信這一點(diǎn)。我將上述查詢用作與另一個(gè)查詢的 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
嘗試上面的查詢并讓我知道結(jié)果。
要根據(jù)類別顯示結(jié)果,您可以簡(jiǎn)單地將查詢分為兩部分:
邏輯示例:
$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.
現(xiàn)在,您可以在不同的 DIV 中使用單獨(dú)的結(jié)果。
<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>
希望你能理解這個(gè)概念。
- 1 回答
- 0 關(guān)注
- 135 瀏覽
添加回答
舉報(bào)