数据库表格:shiti, shititimu, timu, kemu, xuanxiang
根据科目设置一个可以添加试题的页面:(如下图)
具体的题目从数据库中查出并形成一张试卷的形式
考试试题设置:
考试试题设置后台:ksset.php
1 Query($sql);7 $smarty->assign("kemu",$attr);8 $smarty->display("ksset.html");
考试试题设置前端:ksset.html
1 2 3 4 526 27 61考试设置 6 7 8 9 10考试试题设置
11
提交处理页面:kschuli.php
1 Query($sql,1);14 15 //往试题题目表添加具体的题目内容16 //根据科目和数量随机生成17 //查科目18 $all="select code from timu where kemu='{ $kemu}'";19 $aall=$db->Query($all);//里面包含本科目所有题目代号20 21 $attr=array();//存放生成的试题代号22 //根据数量来取23 for($i=0;$i<$shuliang;$i++)24 {25 //随机取代号26 $n=rand(0,count($aall)-1);27 $daihao=$aall[$n][0];28 //判断取出的代号是否重复29 if(in_array($daihao,$attr))30 {31 $i--;//若什么也不添加,循环出的数量会减少,所以若代号重复是,$i减少一次,再加一个32 }33 else34 {35 //$aall[$n][0];36 array_push($attr,$daihao);37 }38 }39 40 41 //往shititimu(试题题目)表添加数据42 //code(自增长), shiti(试题代号)=$code, timu=$v, shunxu=$k43 44 foreach($attr as $k=>$v)45 {46 $shunxu=$k+1;47 $stm="insert into shititimu values('','{ $code}','{ $v}','{ $shunxu}')";48 $db->Query($stm,1);49 }50 header("location:ksset.php");
注意:若该科目的试题数量少于输入的试题数量时,要提醒试题数量不足(如图)
使用ajax来进行处理,处理页面:bijiaosl.php
1 StrQuery($sql);11 12 if($zs>=$sl)13 {14 echo "OK";15 }16 else17 {18 echo "NO";19 }20
形成试卷页面:
形成试卷页面后台:shijuan.php
1 Query($sql); 9 10 $shuzu=array();//存储题目信息11 //判断考试名称的值是否为空12 if(empty($_POST["ksmc"]))13 {14 15 }16 else17 {18 //取出试题的代号19 $code=$_POST["ksmc"];20 $stm="select * from shititimu where shiti='{ $code}'";21 $atm=$db->Query($stm);22 23 //根据代号去查找相应的题目及选项24 foreach($atm as $v)25 {26 //题目代号27 $tmdh=$v[2];28 //题目顺序29 $tmsx=$v[3];30 31 //从题目表中取出试题的题目32 $sname="select name from timu where code='{ $tmdh}'"; 33 $aname=$db->StrQuery($sname);34 35 //从选项表中取出相应的选项36 $sxx="select name,xuanxiang from xuanxiang where timu='{ $tmdh}'";37 $axx=$db->Query($sxx);38 39 $timuall=array("tmsx"=>$tmsx,"tmmc"=>$aname,"tmxx"=>$axx);40 $shuzu[]=$timuall;41 42 }43 44 }45 46 $smarty->assign("shiti",$attr);47 $smarty->assign("timu",$shuzu);48 $smarty->display("shijuan.html");
形成试卷页面前端:shijuan.html
1 2 3 4 520 21试卷页面 6 7 8 9试题详情
10
22 <{ foreach $timu as $v}>23 24
31 32 33 <{ $v.tmsx}>、<{ $v.tmmc}>( )
25 <{ foreach $v.tmxx as $v1}>26 <{ $v1[1]}>:<{ $v1[0]}>
27 <{/foreach}> 28 <{/foreach}>29 30