如何逐个从数据库中检索问题 [英] How to retrieve question from database one by one

查看:69
本文介绍了如何逐个从数据库中检索问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在线测试应用程序。

我的要求是 -



1.问题将从数据库中随机检索。

2.选项是如果我再次开始测试也会洗牌。

3.页面上显示一个问题,然后显示下一个按钮点击下一个问题。



任何人都可以给我解决方案 -

1.如何在页面上一次显示一个问题

2.如何随机播放选项。





提前感谢

I am Developing a on-line test application.
my requirements are-

1. Questions will be retrieved from database randomly.
2. Options are also shuffled if i start the test again.
3. One question at a time is displayed on the page and on next button click next question is displayed.

can any one give me the solution for that-
1. how to display one question at a time on the page
2. how to shuffle options.


thanks in advance

推荐答案

为了随意提取您的问题是您必须在问题表中提供订购标准,自动增加字段(例如 id )非常适合。

然后你可以使用随机数生成器( Random 类)来提取随机数并在查询中使用它:

In order to extract randomly your questions you have to provide an ordering criterion to your table of questions, a auto-increment field (say id) would fit very well.
Then you could use the random number generator (Random class) for extracting a random number and use it in your query:
select question from question_table where id=@random_number



如果您不想重复问题(即选择两个或者在同一测试中多次使用同一个问题)然后看看我的提示中显示的算法:从甲板上随机抽取5张牌 [ ^ ]。


从问题ID(minQId和maxQId)得到最小值和最大值数据库并选择随机ID为:

You get minimun and maximum value of question Id (minQId and maxQId) from database and choose a random ID as:
Random rnd = new Random();
int questionIdToFetch = rnd.Next(minQId, maxQId); 



然后得到完整的问题和显示。



要在下面填充链接将是有用的:

http://stackoverflow.com/questions/273313/randomize- a-listt-in-c-sharp [ ^ ]



如果还有其他问题,请告诉我。


Then get that complete question and display.

To suffle asnwers below link would be useful:
http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp[^]

Let me know if there is any further question.


如何每次获取随机播放选项



How to shuffle options on each get

SELECT * FROM OPTIONS 
WHERE question = @your_question
ORDER BY NEWID()


这篇关于如何逐个从数据库中检索问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆