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 关注
- 120 浏览
添加回答
举报