所需要的数据库表格:shiti, shititimu, timu, kemu, xuanxiang
考试试题的设置:
考试试题后台:ksset.php
<?php
include("../init.inc.php"); include("../DBDA.php");
$db = new DBDA(); $skm = "select * from kemu";
$akm = $db->Query($skm); $smarty->assign("kemu",$akm);
$smarty->display("ksset06.html");
考试试题处理页面:kssetchuli.php
<?php include("../DBDA.php");
$db = new DBDA(); $code = $_POST["code"];
$name = $_POST["name"];
$kemu = $_POST["kemu"];
$shijian = $_POST["shijian"];
$shuliang = $_POST["shuliang"];
$fenzhi = $_POST["fenzhi"]; $sql = "insert into shiti values('{$code}','{$shijian}','{$kemu}','{$name}','{$shuliang}','{$fenzhi}')";
$db->Query($sql,1); $sall = "select code from timu where kemu ='{$kemu}'";
$aall = $db->Query($sall); var_dump($aall); $shuzu = array();//生成的试题代号 for($i=0;$i<$shuliang;$i++)
{
$n = rand(0,count($aall)-1);//0-数组长度的随机数(索引从0开始的)
$daihao = $aall[$n][0]; if(in_array($daihao,$shuzu))
{
$i--;
}
else
{
array_push($shuzu,$daihao);
}
}
foreach($shuzu as $k=>$v)
{
$shunxu = $k+1;
$sttm = "insert into shititimu values('','{$code}','{$v}','{$shunxu}')";
$db->Query($sttm,1);
}
header("location:ksset.php");
考试试题前端显示:ksset06.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>考试信息</title>
<script src="../../jquery-1.11.2.min.js"></script>
</head> <body>
<!--<a href="#" onclick="return confirm('确定要删除吗')">删除</a>-->
<h1>设置考试信息</h1>
<form action="kssetchuli.php" method="post">
<div>请输入考试编号:<input type="text" name="code" /></div></br> <div>请输入考试名称:<input type="text" name="name" /></div></br> <div>请选择考试科目:
<select name="kemu" id="kemu">
<{foreach $kemu as $v}>
<option value="<{$v[0]}>"><{$v[1]}></option>
<{/foreach}>
</select>
</div></br> <div>请输入考试时间:<input type="text" name="shijian" />分钟</div></br> <div>请输入题目数量:<input type="text" name="shuliang" id="sl" /></div></br> <div>请输入题目分值:<input type="text" name="fenzhi" /></div></br> <input type="submit" value="提交" id="tj" onclick="Check()" />
</form>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(e) {
$("#tj").click(function(){
var km = $("#kemu").val();
var sl = $("#sl").val();
var bs = ""; $.ajax({
url:"panduansl.php",
async:false,
data:{km:km,sl:sl},
type:"POST",
dataType:"TEXT",
success: function(data){
bs = data;
}
}); if(bs.trim()=="OK")
{
return true;
}
else
{
alert("该科目下的题目数量不足");
return false;
} }) }); </script>
前端的显示数据包含需要判断的输入该科目下的试题数量的比较:panduansl.php(使用ajax)
<?php include("../DBDA.php");
$db = new DBDA(); $km = $_POST["km"];
$sl = $_POST["sl"]; $sall = "select count(*) from timu where kemu ='{$km}'";
$aall = $db->StrQuery($sall); if($aall>=$sl)//表中的与写进去的比较
{
echo "OK";
}
else
{
echo "NO";
}
形成试卷的相关页面:
形成的试卷后台页面:kstimu.php
<?php
include("../init.inc.php"); include("../DBDA.php");
$db = new DBDA(); $sst = "select * from shiti";
$ast = $db->Query($sst); $shzu = array();//题目信息 if(empty($_POST["ksmc"]))
{ }
else
{
$code = $_POST["ksmc"];//根据他去查shititimu
$stm = "select * from shititimu where shiti='{$code}'";
$atm = $db->Query($stm);
//var_dump($atm);
foreach($atm as $v)
{
$tmdh = $v[2];//代号
$tmsx = $v[3];//顺序 $sname = "select name from timu where code='{$tmdh}'";
$tmmc = $db->StrQuery($sname);
//echo $tmmc; $sxx = "select name,xuanxiang from xuanxiang where timu ='{$tmdh}'";
$axx = $db->Query($sxx);//选项
//var_dump($axx); $tmxx = array("tmsx"=>$tmsx,"tmmc"=>$tmmc,"xuanxiang"=>$axx);
$shzu[] = $tmxx;//往数组添加数据
//var_dump($shzu);
} } $smarty->assign("tm",$shzu);
$smarty->assign("st",$ast);
$smarty->display("kstimu06.html");
形成的试卷前端显示:kstimu06.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head> <body>
<form action="kstimu.php" method="post">
<h1>试题详情</h1>
<div>请选择考试名称:
<select name="ksmc">
<{foreach $st as $v}>
<option value="<{$v[0]}>"><{$v[3]}></option>
<{/foreach}>
</select> <input type="submit" value="查询" />
</div>
</form>
<br />
<div>
<{foreach $tm as $v}>
<div style="font-size:18px; font-weight:bold; color:#906"><{$v.tmsx}> <{$v.tmmc}></div> <{foreach $v.xuanxiang as $v1}>
<div><{$v1[1]}>:<{$v1[0]}></div>
<{/foreach}><br /> <{/foreach}> </div>
</body>
</html>