今天写了一个通过switch进行添加,修过,显示,删除程序,发上来大家看看,哈哈,并且用了smarty模版

这里通过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="提交">&nbsp;&nbsp;
<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="批量删除">&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值