繁体   English   中英

在php在线考试系统中由rand使用订单时重复出现问题

[英]Questions are repeating when used order by rand in php online exam system

在php在线考试系统中由rand使用订单时重复出现问题

if(isset($_SESSION['stdname'])){
    $result=executeQuery("select stdanswer,answered from studentquestion where stdid=".$_SESSION['stdid']." and testid=".$_SESSION['testid']." and qnid=".$_SESSION['qn'].";");
    $r1=mysql_fetch_array($result);
    $result=executeQuery("select * from question where testid=".$_SESSION['testid']." and qnid=".$_SESSION['qn']."order by rand();");
    $r=mysql_fetch_array($result);

在查询中使用关键字DISTINCT

$result=executeQuery("select DISTINCT * from question where testid=".$_SESSION['testid']." and qnid=".$_SESSION['qn']." order by rand();");

mysql_ *也已弃用。 关注@Magnus的评论

代替在查询中使用“ ORDER BY RAND”,抓住所有可能的问题。 将问题放入数组后,请使用shuffle()函数( http://php.net/manual/en/function.shuffle.php )将问题随机化。 然后,您所需要做的就是使用for循环来获取所需数量的问题。

暂无
暂无

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

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