<?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. 添加JSTL 1.2 依赖库

    添加JSTL 1.2 依赖库 JSTL 是一项很有历史的技术,而且版本自Java 5以来长期停留在1.2.但在做简单演示的页面时jstl依然有用,当前我们依然能看到这项技术(在博客.文档的demo里很 ...

  2. Mysql的转义字符

    Mysql的转义字符是"\",即反斜杠,在INSERT语句中,如果被插入的文本中包含反斜杠,那么反斜杠会被吃掉.例如: INSERT INTO tb (id,json) VALUE ...

  3. cocoaPods安装成功终端代码(期间报error: RPC failed; result=56, HTTP code = 200)

    Last login: Sat Oct 15 23:30:24 on ttys002 Sivek_lindeMacBook-Pro:~ Sivek_lin$ sudo gem update --sys ...

  4. @ResponseBody注解与JSON

    MappingJacksonHttpMessageConverter 调用了 objectMapper.writeValue(OutputStream stream, Object)方法,使用@Res ...

  5. spring+springmvc+maven+mybatis整合

    jar包依赖:网址search.maven.org 1.spring :spring-core            2. myhabits:myhabits 3.整合spring和myhabits: ...

  6. php正则匹配中文

    <?php $str = '你是我的+****xiaopingguo _ 23947237 _+冠军终归这里'; preg_match_all('/[\x{4e00}-\x{9fa5}A-Za- ...

  7. UI_APPEARANCE_SELECTOR 延伸

    iOS后属性带UI_APPEARANCE_SELECTOR 可以统一设置全局作用 例如: 1>开关控件 @property(nullable, nonatomic, strong) UIColo ...

  8. 伪分布重新格式化hdfs

    重新格式化hdfs系统的方法: (1)查看hdfs-ste.xml: <span style="font-size:18px;"><property> &l ...

  9. java基础值向上向下转型

    1.父类引用可以指向子类对象,子类引用不能指向父类对象. 2.向上转型:子类引用的对象转换为父类类型称为向上转型,把子类对象直接赋给父类引用叫upcasting,向上转型不用强制转型(类似于低精度赋给 ...

  10. 对jquery新增加的class绑定事件

    当页面加载时,就会注册所有的事件,后面通过jquery新增的内容(<div class="item"></div>),再对新增的添加事件$(".i ...