簡體   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