您的位置:首页 > 其它

今天写了一个通过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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐