今天写了一个通过switch进行添加,修过,显示,删除程序,发上来大家看看,哈哈,并且用了smarty模版
2009-05-28 20:11
731 查看
这里通过switch来实现具体功能的程序:new_content.php
<?php
include_once("conn_inc.php");
include_once("smarty_inc.php");
$date=date('Y-m-d');
$act=$_REQUEST['act'];
$id=$_REQUEST['id'];
switch ($act){
case "add":
$aFaid=$_REQUEST['into'];
$query=mysql_query("insert into `new_content`(`name`,`zaiyao`,`content`,`date_time`) values ('$aFaid[name]','$aFaid[zaiyao]','$aFaid[content]','$date')");
if ($query) {
echo "<script>alert('添加成功!')</script>";
echo "<script>location.href='new_content_add.php'</script>";
}else {
echo "<script>alert('添加失败!')</script>";
echo "<script>location.href='new_content.php'</script>";
}
break;
case "list":
$query=mysql_query("select * from `new_content` where id='$id'");
$row=@mysql_fetch_array($query);
$id=$row[id];
$name=$row[name];
$zaiyao=$row[zaiyao];
$content=$row[content];
$date_time=$row[date_time];
$smarty->assign("id",$id);
$smarty->assign("name",$name);
$smarty->assign("zaiyao",$zaiyao);
$smarty->assign("content",$content);
$smarty->assign("date_time",$date_time);
$smarty->display("new_content_dncdist.tpl.html");
break;
case "update":
$edit=$_REQUEST['into'];
$sql="update `new_content` set name='$edit[name]',zaiyao='$edit[zaiyao]',content='$edit[content]',date_time='$date' where id='$id'";
$query=mysql_query($sql);
if ($query) {
echo "<script>alert('更新成功!')</script>";
echo "<script>location.href='new_content_dist.php'</script>";
}else {
echo "更新失败!";
}
break;
case "delete":
$del=$_REQUEST['del'];
$id=implode(",",$del);
$query=mysql_query("delete from `new_content` where id in (".$id.")");
if ($query) {
echo "<script>alert('删除成功!')</script>";
echo "<script>location.href='new_content_dist.php'</script>";
}
break;
}
?>
以下是实现页面添加的程序:new_content_add.php
<?php
include_once("conn_inc.php");
include_once("smarty_inc.php");
$smarty->display("new_content.tpl.html");
?>
以下是实现页面添加时要用的模版程序:
<html>
<head>
<title>添加内容</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form action="new_content.php?act=add" method="POST">
<table align="center" width="80%" border="1">
<tr>
<td>标题:</td>
<td><input type="text" name="into[name]" size="55"></td>
</tr>
<tr>
<td>摘要:</td>
<td><textarea name="into[zaiyao]" rows="6" cols="45"></textarea></td>
</tr>
<tr>
<td>内容:</td>
<td><textarea name="into[content]" rows="10" cols="45"></textarea></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" name="submit" value="提交">
<input type="reset" name="reset" value="重置">
</center></td>
</tr>
</table>
</form>
</body>
</html>
以下是实现显示的页面:new_content_dist.php
<?php
require_once("conn_inc.php");
require_once("smarty_inc.php");
$query=mysql_query("select * from new_content order by id desc");
while ($row=mysql_fetch_array($query)){
$array[]=array("id"=>"$row[id]","name"=>"$row[name]","date_time"=>"$row[date_time]");
}
$smarty->assign("array",$array);
$smarty->display("new_content_dist.tpl.html");
?>
以下是实现显示页面的模版程序: new_content_dist.tpl.html
<html>
<head>
<title>文章列表</title>
</head>
<body>
<form action="new_content.php?act=delete" method="POST">
<table align="center" border="1" width="80%">
<tr>
<td>ID</td>
<TD>标题</TD>
<td>日期</td>
<td>更新</td>
<td>删除</td>
</tr>
{foreach from=$array item=values}
<tr>
<td>{$values.id}</td>
<td>{$values.name}</td>
<td>{$values.date_time}</td>
<td><a href="new_content.php?act=list&id={$values.id}">更新</a></td>
<td><input type="checkbox" value="{$values.id}" name="del[]">删除</td>
</tr>
{/foreach}
<tr>
<td colspan="5" align="right"><input type="submit" name="submit" value="批量删除"> </td>
</tr>
</table>
</form>
</body>
</html>
<?php
include_once("conn_inc.php");
include_once("smarty_inc.php");
$date=date('Y-m-d');
$act=$_REQUEST['act'];
$id=$_REQUEST['id'];
switch ($act){
case "add":
$aFaid=$_REQUEST['into'];
$query=mysql_query("insert into `new_content`(`name`,`zaiyao`,`content`,`date_time`) values ('$aFaid[name]','$aFaid[zaiyao]','$aFaid[content]','$date')");
if ($query) {
echo "<script>alert('添加成功!')</script>";
echo "<script>location.href='new_content_add.php'</script>";
}else {
echo "<script>alert('添加失败!')</script>";
echo "<script>location.href='new_content.php'</script>";
}
break;
case "list":
$query=mysql_query("select * from `new_content` where id='$id'");
$row=@mysql_fetch_array($query);
$id=$row[id];
$name=$row[name];
$zaiyao=$row[zaiyao];
$content=$row[content];
$date_time=$row[date_time];
$smarty->assign("id",$id);
$smarty->assign("name",$name);
$smarty->assign("zaiyao",$zaiyao);
$smarty->assign("content",$content);
$smarty->assign("date_time",$date_time);
$smarty->display("new_content_dncdist.tpl.html");
break;
case "update":
$edit=$_REQUEST['into'];
$sql="update `new_content` set name='$edit[name]',zaiyao='$edit[zaiyao]',content='$edit[content]',date_time='$date' where id='$id'";
$query=mysql_query($sql);
if ($query) {
echo "<script>alert('更新成功!')</script>";
echo "<script>location.href='new_content_dist.php'</script>";
}else {
echo "更新失败!";
}
break;
case "delete":
$del=$_REQUEST['del'];
$id=implode(",",$del);
$query=mysql_query("delete from `new_content` where id in (".$id.")");
if ($query) {
echo "<script>alert('删除成功!')</script>";
echo "<script>location.href='new_content_dist.php'</script>";
}
break;
}
?>
以下是实现页面添加的程序:new_content_add.php
<?php
include_once("conn_inc.php");
include_once("smarty_inc.php");
$smarty->display("new_content.tpl.html");
?>
以下是实现页面添加时要用的模版程序:
<html>
<head>
<title>添加内容</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form action="new_content.php?act=add" method="POST">
<table align="center" width="80%" border="1">
<tr>
<td>标题:</td>
<td><input type="text" name="into[name]" size="55"></td>
</tr>
<tr>
<td>摘要:</td>
<td><textarea name="into[zaiyao]" rows="6" cols="45"></textarea></td>
</tr>
<tr>
<td>内容:</td>
<td><textarea name="into[content]" rows="10" cols="45"></textarea></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" name="submit" value="提交">
<input type="reset" name="reset" value="重置">
</center></td>
</tr>
</table>
</form>
</body>
</html>
以下是实现显示的页面:new_content_dist.php
<?php
require_once("conn_inc.php");
require_once("smarty_inc.php");
$query=mysql_query("select * from new_content order by id desc");
while ($row=mysql_fetch_array($query)){
$array[]=array("id"=>"$row[id]","name"=>"$row[name]","date_time"=>"$row[date_time]");
}
$smarty->assign("array",$array);
$smarty->display("new_content_dist.tpl.html");
?>
以下是实现显示页面的模版程序: new_content_dist.tpl.html
<html>
<head>
<title>文章列表</title>
</head>
<body>
<form action="new_content.php?act=delete" method="POST">
<table align="center" border="1" width="80%">
<tr>
<td>ID</td>
<TD>标题</TD>
<td>日期</td>
<td>更新</td>
<td>删除</td>
</tr>
{foreach from=$array item=values}
<tr>
<td>{$values.id}</td>
<td>{$values.name}</td>
<td>{$values.date_time}</td>
<td><a href="new_content.php?act=list&id={$values.id}">更新</a></td>
<td><input type="checkbox" value="{$values.id}" name="del[]">删除</td>
</tr>
{/foreach}
<tr>
<td colspan="5" align="right"><input type="submit" name="submit" value="批量删除"> </td>
</tr>
</table>
</form>
</body>
</html>
相关文章推荐
- 一个使用GridView显示数据,并且可以进行添加、修改、删除操作的例子
- 早上学习了一个smarty局部刷新的例子发上来大家看看,过两天我会把它与数据库相互结合起来写成功发过来的
- 自己写了一个把文章标题从数据库中读出,并且赋值给一个数组,最后通过smarty循环显示出来
- 今天带来的是一个对图书编号和价格设定程序 不是很完善希望大家给与建议进行修改
- 在一个ul中添加新的li,在li中添加文本框并且进行删除操作
- 用jsp实现一个简单的购物车web应用系统。实现的添加购物商品,删除购物商品并且显示购物车信息。
- 定义一个不受计算机字长限制的整数类INT,要求INT与INT以及INT与C++基本数据类型int之间能进行+、-、×、÷和=运算,并且能通过cout输出INT类型的值。(持续添加)
- 用C语言模拟实现一个通讯录,要求实现其添加、删除、修改、查找、显示和排序联系人信息的功能
- 编写一个程序,在E盘下创建一个abc.txt的文本文档,通过输出流在文档内添加数据,然后在把abc.txt复制到F盘下
- 让一个程序托盘显示,并且右键托盘图标可以弹出菜单
- 通过LDAP在AD域控上进行添加、删除、修改、查询等各种操作
- 【通讯录系统】:实现一个通讯录(可添加、删除、修改、查找、显示、清空、排序)
- 通过CommandBuilder对DataSet数据进行添加、修改、删除
- 一个简单的将GUI程序的log信息输出到关联的Console窗口中(AllocConsole SetConsoleTitle WriteConsole 最后用ShowWindow(GetConsoleWindow)进行显示)
- 在部署一个IIS7程序时的问题 模块列表中不存在为此处理程序指定的一个或多个模块。如果您尝试添加脚本 映射,则 IsapiModule 或 CgiModule 不会显示在模块列表中
- 通过上下文菜单的方式进行删除添加日记的操作
- 今天给大家说一个我做UI特效的小技巧,先来看看效果吧(录屏有点渣,所以质量有折扣)
- (1)写一个程序,用于分析一个字符串中各个单词出现的频率,并将单词和它出现的频率输出显示。(单词之间用空格隔开,如“Hello World My First Unit Test”); (2)编写单元测试进行测试; (3)用ElcEmma查看代码覆盖率,要求覆盖率达到100%。
- 不知道大家用什么工具对Web程序进行不同版本的IE测试,向大家介绍一个工具,感觉还不错也许大家早就知道
- 一个能一句话添加header和Footer,并且能滑动删除和交换Item的RecyclerView