简体   繁体   English

如何从mysql中随机地从10,000个中选择最多10个数据,即使用php一次选择一个?

[英]How to select maximum of 10 data out of 10,000 from mysql randomly, i.e one at a time using php?

Goodday all, please am developing an online game like 'who want to be a millionaire'. 大家好,请开发一款类似“谁想成为百万富翁”的在线游戏。 I have 10,000 questions with answers, in mysql database and I want the players to answer 10 shufled questions but one at a time with timer.At the end of the ten questions the page should echo number of questions answered correctly. 我在mysql数据库中有10,000个带有答案的问题,我希望玩家回答10个问题,但一次用计时器回答一个。在十个问题的末尾,页面应回显正确回答的问题数。 Mysql table look does: Mysql表看起来确实:

question_id  question  optiona  optionb  optionc  optiond  answer

I have tried the following but no limitation to the number of questions 我已经尝试了以下方法,但问题数量没有限制

I will appreciate it, if anyone could reply soonest. 如果有人能尽快答复,我将不胜感激。

You can use mysql order by rand function 您可以通过rand函数使用mysql order

Eg: General Sample 例如: 一般样本

If the table becomes too big there is a faster way to do it: 如果表太大,则有一种更快的方法:

http://www.dasprids.de/blog/2008/06/07/fetching-random-rows-of-mysql-efficiently http://www.dasprids.de/blog/2008/06/07/fetching-random-rows-of-mysql-effectively

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM