Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php测验中的随机问题,无重复问题_Php - Fatal编程技术网

php测验中的随机问题,无重复问题

php测验中的随机问题,无重复问题,php,Php,这是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($res

这是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']." Order by rand() ");
$r=mysql_fetch_array($result);
1. > 2. > 3. > 4. > 有了这段代码,问题是以随机的方式出现的,但实际的问题是问题不断重复,如何从上面的代码中解决这个重复的问题

--

--表
问题的表结构
如果不存在,则创建表格
问题
(
testid
bigint(20)非空默认值“0”,
qnid
int(11)非空默认值“0”,
question
varchar(500)默认为空,
optiona
varchar(100)默认为空,
optionb
varchar(100)默认为空,
optionc
varchar(100)默认为空,
optiond
varchar(100)默认为空,
correctanswer
enum('optiona'、'optionb'、'optionc'、'optiond')默认为空,
标记
int(11)默认为空, 主键(
testid
qnid
) )ENGINE=InnoDB默认字符集=1

--

--正在转储表
问题的数据
如果存在,则删除表格
studentquestion
; /*!40101 SET@saved_cs_client=@@character_SET_client/; /!40101集合字符\集合\客户端=utf8/; 创建表格
studentquestion
(
stdid
bigint(20)非空默认值“0”,
testid
bigint(20)非空默认值“0”,
qnid
int(11)非空默认值“0”,
answered
enum('answered'、'unanswered'、'review')默认为空,
stdanswer
enum('optiona','optionb','optionc','optiond')默认为空, 主键(
stdid
testid
qnid
), 键
testid
testid
qnid
), 约束
studentquestion\u ibfk\u 1
外键(
stdid
)引用
student
stdid
), 约束
studentquestion\u ibfk\u 2
外键(
testid
qnid
)参考
question
testid
qnid
) )ENGINE=InnoDB默认字符集=1; /!40101 SET character_SET_client=@saved_cs_client*/

--

--正在转储表的数据
studentquestion
锁定表格
studentquestion
WRITE; /*!40000 ALTER TABLE
studentquestion
DISABLE key/; /!40000 ALTER TABLE
studentquestion
ENABLE key*/;
解锁表格

使用上述代码,问题也会重复出现对不起。编辑了第一个查询。请根据以上编辑的第一个查询再次检查。我做了更改,但现在当测试开始时,问题及其选项不会显示。我进一步添加了代码。请再次查看我编辑的问题。是。你能不能也提供表格结构?
// select the questions id's already answered by the current student
$result=executeQuery("select qnid, stdanswer,answered from studentquestion where stdid=".$_SESSION['stdid']." and testid=".$_SESSION['testid'].";");
$already_answered_qns = array();
while($r1=mysql_fetch_array($result))
{
    array_push($already_answered_qns, $r1['qnid']);
}


// select a question excluding the already answered questions
$result=executeQuery("select * from question where testid=".$_SESSION['testid']." and qnid not in (".implode(', ', $already_answered_qns).") Order by rand() ");
$r=mysql_fetch_array($result);