这是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.> 使用此代码,问题以随机的方式出现,但实际问题是如何从上面的代码中重复解决这个重复问题的问题
-
question
CREATE TABLE IF NOT NOT EXISTS question
(
testid
bigint(20)NOT NULL DEFAULT'0',
qnid
int(11)NOT NULL DEFAULT'0',
question
varchar(500)DEFAULT NULL,
optiona
varchar(100)DEFAULT NULL,
optionb
varchar(100)DEFAULT NULL,
optionc
varchar(100)DEFAULT NULL,
optiond
varchar(100)DEFAULT NULL,
correctanswer
枚举('optiona','optionb','optionc','optiond')DEFAULT NULL,
marks
int(11)DEFAULT NULL,
PRIMARY KEY(testid
,qnid
)
)ENGINE = InnoDB DEFAULT CHARSET = latin1;
-
question
DROP TABLE IF EXISTS studentquestion
;
/ *!40101 SET @saved_cs_client = @@ character_set_client /;
/ !40101 SET character_set_client = utf8 /;
CREATE TABLE studentquestion
(
stdid
bigint(20)NOT NULL DEFAULT'0',
testid
bigint(20)NOT NULL DEFAULT'0',
qnid
int(11)NOT NULL DEFAULT'0',
answered
枚举('已回答','未接听','审核')DEFAULT NULL,
stdanswer
枚举('optiona','optionb','optionc','optiond')DEFAULT NULL,
PRIMARY KEY(stdid
,testid
,qnid
),
KEY testid
(testid
,qnid
),
约束studentquestion_ibfk_1
外键(stdid
)参考student
(stdid
),
约束studentquestion_ibfk_2
外键(testid
,qnid
)参考question
(testid
,qnid
)
)ENGINE = InnoDB DEFAULT CHARSET = latin1;
/ !40101 SET character_set_client = @saved_cs_client * /;
-
studentquestion
LOCK TABLES studentquestion
WRITE;
/ *!40000 ALTER TABLE studentquestion
DISABLE KEYS /;
/ !40000 ALTER TABLE studentquestion
ENABLE KEYS * /;
解锁表格;
答案 0 :(得分:-1)
// 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);