当兰德在php在线考试系统中按顺序使用时,问题会重复出现

当兰德在php在线考试系统中按顺序使用时,问题会重复出现,php,mysql,Php,Mysql,当兰德在php在线考试系统中按顺序使用时,问题会重复出现 if(isset($_SESSION['stdname'])){ $result=executeQuery("select stdanswer,answered from studentquestion where stdid=".$_SESSION['stdid']." and testid=".$_SESSION['testid']." and qnid=".$_SESSION['qn'].";"); $r1=mysq

当兰德在php在线考试系统中按顺序使用时,问题会重复出现

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()函数()将问题随机化。然后,您所需要做的就是使用for循环来获取所需数量的问题。

不要使用不推荐使用且不安全的
mysql.*
-函数。自PHP5.5(2013年)起,它们就被弃用,并在PHP7(2015年)中被完全删除。改用MySQLi或PDO。1.
mysql_*
是一个不推荐使用的库(在PHP5.5(2013年)中),在更新版本的PHP中被删除(在PHP7(2015年))。所以请尽快升级你自己。2.很可能多次
rand()
搜索实际发生的情况时会产生相同的数字。使用
distinct
operator@SalimIbrogimovDistinct在列而不是行上工作,所以在这里使用它是绝对无用的。1) 停止使用mysql,因为它已被弃用。2) rand可以提供重复的结果,因为它提供的是随机行,而不是唯一的随机行。3) 对其中一列使用
groupby
,然后按列而不是行排序。因此,根据distinct,这两行是不同的,这是问题1,这是问题2,因此您将再次获得重复列。我尝试通过从mysql转换到mysqli来转换代码,但仍然没有任何结果