<?php
//将题目表显示在页面
include("../init.inc.php"); include("../DBDA.php");
$db = new DBDA(); $sql = "select * from timu";
$attr = $db->Query($sql); $smarty->assign("shuju",$attr); $smarty->display("zhu0603pm.html");

主页前段显示页面:zhu0603pm.html

<html>
<head>
<meta charset="utf-8" />
</head>
<title>Smarty的增删改查</title> <body>
<h1>主页面</h1>
<br /> <table border="1" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>题目名称</td>
<td>答案</td>
<td>科目</td>
<td>难度</td>
<td>类型</td>
<td>操作</td>
</tr> <{foreach $shuju as $v}>
<tr>
<td><{$v[1]}></td>
<td><{$v[2]}></td>
<td><{$v[3]}></td>
<td><{$v[4]}></td>
<td><{$v[5]}></td>
<td><a href="shanchu.php?code=<{$v[0]}>">删除</a>&nbsp;&nbsp;<a href="xiugai.php?code=<{$v[0]}>">修改</a></td>
</tr>
<{/foreach}>
</table>
<br>
<a href="tianjia.php">添加数据</a> </body>
</html>

添加后台页面:tianjia.php

<?php
//添加数据
include("../init.inc.php"); include("../DBDA.php");
$db = new DBDA(); $sql = "select * from kemu";
$attr = $db->Query($sql); $sqlnd = "select * from nandu";
$attrnd = $db->Query($sqlnd); $sqllx = "select * from leixing";
$attrlx = $db->Query($sqllx); $smarty->assign("kemu",$attr);
$smarty->assign("nandu",$attrnd);
$smarty->assign("type",$attrlx); $smarty->display("tianjia03pm.html");

添加处理页面:tianjiachuli.php

<?php

include("../DBDA.php");
$db = new DBDA(); $name = $_POST["name"];
$daan = $_POST["daan"];
$kemu = $_POST["kemu"];
$nandu = $_POST["nandu"];
$type = $_POST["type"]; $a = $_POST["a"];
$b = $_POST["b"];
$c = $_POST["c"];
$d = $_POST["d"]; //添加题目
$sql = "insert into timu values('','{$name}','{$daan}','{$kemu}','{$nandu}','{$type}')"; if($db->Query($sql,1))
{
//添加选项
$id = $db->conn->insert_id;//去添加成功的主键值 $sqla = "insert into xuanxiang values('','{$a}','A','{$id}')";
$db->Query($sqla,1);
$sqlb = "insert into xuanxiang values('','{$b}','B','{$id}')";
$db->Query($sqlb,1);
$sqlc = "insert into xuanxiang values('','{$c}','C','{$id}')";
$db->Query($sqlc,1);
$sqld = "insert into xuanxiang values('','{$d}','D','{$id}')";
$db->Query($sqld,1); header("location:tianjia.php"); }
else
{
echo "添加失败";
}

添加前段显示页面:tianjia03pm.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>Smarty的增删改查</title>
</head> <body>
<h1>添加数据</h1>
<form action="tianjiachuli.php" method="post"> <div>输入题目名称:<input type="text" name="name" /></div><br /> <div>选项A:&nbsp;&nbsp;<input type="text" name="a" /></div>
<div>选项B:&nbsp;&nbsp;<input type="text" name="b" /></div>
<div>选项C:&nbsp;&nbsp;<input type="text" name="c" /></div>
<div>选项D:&nbsp;&nbsp;<input type="text" name="d" /></div><br /> <div>添加答案:&nbsp;&nbsp;<input type="text" name="daan" /></div><br /> <div>选择科目:&nbsp;&nbsp;
<select name="kemu">
<{foreach $kemu as $v}>
<option value="<{$v[0]}>"><{$v[1]}></option>
<{/foreach}>
</select>
</div><br /> <div>选择题目难度:
<select name="nandu">
<{foreach $nandu as $v}>
<option value="<{$v[0]}>"><{$v[1]}></option>
<{/foreach}>
</select>
</div><br /> <div>选择题目类型:
<select name="type">
<{foreach $type as $v}>
<option value="<{$v[0]}>"><{$v[1]}></option>
<{/foreach}>
</select>
</div> <br /> <input type="submit" value="提交" /> </form>
<br />
<a href="zhupm.php">返回主页</a>
</body>
</html>

删除后台页面:shanchu.php

<?php

include("../DBDA.php");
$db = new DBDA();
$code = $_GET["code"]; $sql = "delete from xuanxiang where timu = '{$code}'";
$db->Query($sql,1); $sql = "delete from timu where code = '{$code}'";
$db->Query($sql,1); header("location:zhupm.php");

修改后台页面:xiugai.php

<?php
include("../init.inc.php"); include("../DBDA.php");
$db = new DBDA();
$code = $_GET["code"]; $sqltm = "select * from timu where code='{$code}'";
$attrtm = $db->Query($sqltm); $sqlxx = "select * from xuanxiang where timu='{$code}'";
$attrxx = $db->Query($sqlxx); $sqlkm = "select * from kemu";
$attrkm = $db->Query($sqlkm); $sqlnd = "select * from nandu";
$attrnd = $db->Query($sqlnd); $sqllx = "select * from leixing";
$attrlx = $db->Query($sqllx); $smarty->assign("code",$code);
$smarty->assign("timu",$attrtm);
$smarty->assign("xuan",$attrxx);
$smarty->assign("kemu",$attrkm);
$smarty->assign("nandu",$attrnd);
$smarty->assign("type",$attrlx); $smarty->display("xiugai03pm.html");

修改处理页面:xiugaichuli.php

<?php
include("../init.inc.php"); include("../DBDA.php");
$db = new DBDA(); $code = $_POST["code"];
$name = $_POST["name"];
$daan = $_POST["daan"];
$kemu = $_POST["kemu"];
$nandu = $_POST["nandu"];
$type = $_POST["type"]; //修改题目
$sqltm = "update timu set name='{$name}',daan='{$daan}',kemu='{$kemu}',nandu='{$nandu}',type='{$type}' where code='{$code}'";
//echo $sqltm;
if($db->Query($sqltm,1))
{
//删除选项
$sdxx = "delete from xuanxiang where timu='{$code}'";
$db->Query($sdxx,1); if(!empty($_POST["A"]))
{
$a = $_POST["A"];
$sqla = "insert into xuanxiang values('','{$a}','A','{$code}')";
$db->Query($sqla,1);
}
if(!empty($_POST["B"]))
{
$b = $_POST["B"];
$sqlb = "insert into xuanxiang values('','{$b}','B','{$code}')";
$db->Query($sqlb,1);
}
if(!empty($_POST["C"]))
{
$c = $_POST["C"];
$sqlc = "insert into xuanxiang values('','{$c}','C','{$code}')";
$db->Query($sqlc,1);
}
if(!empty($_POST["D"]))
{
$d = $_POST["D"];
$sqld = "insert into xuanxiang values('','{$d}','D','{$code}')";
$db->Query($sqld,1);
} header("location:zhupm.php");
}
else
{
echo "修改失败";
}

修改前段显示页面:xiugai03pm.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>Smarty的增删改查</title>
</head> <body>
<h1>修改数据</h1>
<form action="xiugaichuli.php" method="post">
<input type="hidden" name="code" value="<{$timu[0][0]}>" />
<div>输入题目名称:<input type="text" name="name" value="<{$timu[0][1]}>" /></div><br /> <{foreach $xuan as $v}>
<div>选项名称:<{$v[2]}><input type="text" value="<{$v[1]}>" name="<{$v[2]}>" ></div>
<{/foreach}> <div>添加答案:&nbsp;&nbsp;<input type="text" name="daan" value="<{$timu[0][2]}>"/></div><br /> <div>选择科目:&nbsp;&nbsp;
<select name="kemu">
<{foreach $kemu as $v}>
<{if $v[0]==$timu[0][3]}>
<option selected="selected" value="<{$v[0]}>"><{$v[1]}></option>
<{else}>
<option value="<{$v[0]}>"><{$v[1]}></option>
<{/if}>
<{/foreach}>
</select>
</div><br /> <div>选择题目难度:
<select name="nandu">
<{foreach $nandu as $v}>
<{if $v[0]==$timu[0][4]}>
<option selected="selected" value="<{$v[0]}>"><{$v[1]}></option>
<{else}>
<option value="<{$v[0]}>"><{$v[1]}></option>
<{/if}>
<{/foreach}>
</select>
</div><br /> <div>选择题目类型:
<select name="type">
<{foreach $type as $v}>
<{if $v[0]==$timu[0][5]}>
<option selected="selected" value="<{$v[0]}>"><{$v[1]}></option>
<{else}>
<option value="<{$v[0]}>"><{$v[1]}></option>
<{/if}>
<{/foreach}>
</select>
</div> <br />
<input type="submit" value="提交" /> </form>
<br />
<a href="zhupm.php">返回主页</a>
</body>
</html>

Smarty练习增删改的更多相关文章

  1. 6月4 Smarty练习增删改

    练习Smarty的增删改所需要用到的数据库名称:timu,xuanxiang,kemu,nandu,leixing,然后使用smarty模板将前端后后台分割开来: 主页后台页面:zhupm.php & ...

  2. smarty练习:数据的增删改

    根据数据库中的三张表格:timu,xuanxiang,kemu来进行数据的增删改查,并且使用smarty模版将前端与后台分离开来 三张表格: 主页面后台 main.php: <?php //引入 ...

  3. PHP程序中使用PDO对象实现对数据库的增删改查操作的示例代码

    PHP程序中使用PDO对象实现对数据库的增删改查操作(PHP+smarty) dbconn.php <?php //------------------------使用PDO方式连接数据库文件- ...

  4. PHP-------smaty 增删改查

    smaty 增删改查 smarty-----main文件夹,是放php文件的--------templates文件夹是放html文件的 我们访问的页面是php页面,PHP页面需要使用smarty模板, ...

  5. Dapper逆天入门~强类型,动态类型,多映射,多返回值,增删改查+存储过程+事物案例演示

    Dapper的牛逼就不扯蛋了,答应群友做个入门Demo的,现有园友需要,那么公开分享一下: 完整Demo:http://pan.baidu.com/s/1i3TcEzj 注 意 事 项:http:// ...

  6. ASP.NET从零开始学习EF的增删改查

           ASP.NET从零开始学习EF的增删改查           最近辞职了,但是离真正的离职还有一段时间,趁着这段空档期,总想着写些东西,想来想去,也不是很明确到底想写个啥,但是闲着也是够 ...

  7. 无限分级和tree结构数据增删改【提供Demo下载】

    无限分级 很多时候我们不确定等级关系的层级,这个时候就需要用到无限分级了. 说到无限分级,又要扯到递归调用了.(据说频繁递归是很耗性能的),在此我们需要先设计好表机构,用来存储无限分级的数据.当然,以 ...

  8. MongoDB下载安装与简单增删改查

    Windows下MongoDB的安装和配置.启动和停止 下载地址:MongoDB的官方下载网址是:https://www.mongodb.org/downloads 安装步骤1. 点击下载的mongo ...

  9. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(9)-MVC与EasyUI结合增删改查

    系列目录 文章于2016-12-17日重写 在第八讲中,我们已经做到了怎么样分页.这一讲主要讲增删改查.第六讲的代码已经给出,里面包含了增删改,大家可以下载下来看下. 这讲主要是,制作漂亮的工具栏,虽 ...

随机推荐

  1. Epidemic in Monstropolis

    Epidemic in Monstropolis 题目链接:http://codeforces.com/contest/733/problem/C 贪心 新序列的m个数肯定是由原序列的连续的m个子序列 ...

  2. 【NOIP2011提高组】选择客栈

    题目不附了,是一个单纯的ST模型,但是考验各种常数优化. 最大的优化是对于同颜色的客栈来说,如果1号和2号成功配对了,那么1和3,1和4都可以成功配对,那么只要找到一对成功配对的,我们就直接加上剩下的 ...

  3. hdu 2188 选拔志愿者(sg博弈)

    Problem Description 对于四川同胞遭受的灾难,全国人民纷纷伸出援助之手,几乎每个省市都派出了大量的救援人员,这其中包括抢险救灾的武警部队,治疗和防疫的医护人员,以及进行心理疏导的心理 ...

  4. emguCv3.x 实现字符分割,轮廓检测

    /// <summary> /// 获取区域 /// </summary> /// <param name="bitmap"></para ...

  5. Ecstore安装篇-2.单机部署【linux】

    单机部署实施-linux 单机部署实施-linux author :James,jimingsong@vip.qq.com since :2015-03-02 系统环境需求 软件来源 底层依赖 1. ...

  6. EFI、GPT和BIOS、MBR

    用了数十年的PC机主板架构是BIOS模式.但在2004年,微软和英特尔共同推出一种名为可扩展固件接口(EFI)的主板升级换代方案.EFI,即可扩展固件接口(Extensible Firmware In ...

  7. linux 调整文件系统大小 LVM

    fuser -m /home umount /home lvreduce -L 150G /dev/mapper/centos-home lvextend -L +300G /dev/mapper/c ...

  8. OC基础面试题

    1.iOS中delegate代理对象使用weak 之前不停的使用assign,今天在调试一段的时候,发现使用assgin的时候程序会crash,报错EXC_BAD_ACCESS, 经过一番研讨,发明如 ...

  9. date格式化

    Linux: [ghsea@localhost ~]date +%Y:%m:%d [ghsea@localhost ~]date +%Y-%m%d [ghsea@localhost ~]date +% ...

  10. C#使用LitJson解析JSON(转)

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于JavaScript(Standard ECMA-262 3rd Edition - Decembe ...