smarty实现的增删改查
2011-11-24 21:33
169 查看
今天写的程序………………此处省略好多字吧,难以言表…………
*.php
<?PHP
include("conn.php");
include("./init.inc.php");
include("./fckeditor/fckeditor.php");
//从php文件分配标量模板变量
//$id=$_REQUEST['id'];
$page_title="新闻管理系统";
$tpl->assign("page_title",$page_title);
//从php文件分配数组到模板
$sql= "SELECT * FROM `news`";
//echo $sql;
$result=$mysqli->query($sql);
$news=array();
while($row=$result->fetch_assoc()){
$news[]=$row;
//转换成索引的数组
}
$tpl->assign("news",$news);
//根据地址栏的参数判断使用的模板
function editor($name,$value){
global $tpl;
$editor=new Fckeditor($name);
$editor -> BasePath='./fckeditor/';
//工具按钮设置
$editor -> ToolbarSet="Default";
//设置它的宽度
$editor -> Width='500px';
//设置它的高度
$editor-> Height='600px';
$editor->value=$value;
$editor->confit['AutoDetecLanguage']=true;
$editor->Confit['DefaultLanguage']='en';
//生成
$fck=$editor->CreateHtml();
$tpl->assign("editor",$fck);
}
$action=$_REQUEST['action'];
switch($action){
case 'addnewview':
$tpl->assign('page_title','添加新闻');
$tpl->assign('content_title','新闻管理登陆');
$tpl->assign('actionvalue','addnews');
//$tpl->assign('actionvalue','updatenews');
editor("content","");
//editor('content','');//调用编辑器,并定义文本域名为content(与下面addnews中的$_REQUEST['content']对应
$tpl->display("addNew.html");
break;
case "addnews":
$content=$_POST['content'];
$title=$_POST['title'];
echo $title;
echo $content;
$sql3="INSERT INTO news(title,content,date) values('{$title}','{$content}',now())";
echo $sql3;
$mysqli->query($sql3);
header("location:index.php");
break;
case "updatenews":
//执行更新操作
$bh=$_REQUEST['id'];
$tpl->assign('page_title','编辑新闻');
$tpl->assign('content_title','管理新闻');
$tpl->assign("id",$bh);
//进行赋值
echo $bh;
//获取要编辑新闻的id
//把新闻分别显示出来
$sql4="select * from news where id='{$bh}'";
$result=$mysqli->query("$sql4");
$rs=$result->fetch_assoc();
echo $rs['title'];
echo $rs['content'];
$tpl->assign("title",$rs['title']);
$tpl->assign('actionvalue','upafter');
//修改之后提交
editor("content",$rs['content']);
$tpl->display("addNew.html");
//调用编辑器,把内容进行赋值
break;
case "upafter":
$bh=$_REQUEST['id'];
echo $bh;
$title=$_REQUEST['title'];
echo $title;
$content=$_REQUEST['content'];
echo $content;
if(isset($_POST['submit'])){
$sql="update news set title='$title',content='$content',date=NOW() where id='{$bh}'";
echo $sql;
$mysqli->query($sql);
}
$tpl->display("index.html");
break;
case "delnews":
$arr=$_POST['checkbox'];
print_r($arr);
for($i=0;$i<count($arr);$i++){
$sql4="delete from news where id='{$arr[$i]}'";
$result=$mysqli->query("$sql4");
echo $sql4.'****';
}
header("location:index.php");
break;
//分配模板变量
//制定模板变量
default:
$tpl->assign("page_title","新闻管理");
$tpl->assign("content_title","新闻管理");
$tpl->assign("actionvalue","delnews");
//$sql="delete * from news where id='{$id}'";
//$result=$mysqli->query($sql);
//$result->fetch_assoc();
//$sql1="select * from news";
//$result=$mysqli->query($sql1);
//while($row=$reuslt->fetch_assoc()){
//$news[]=$row;
//}
$tpl->assign("news",$news);
$tpl->display("index.html");
}
?>
*.html
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title><{$page_title}></title>
<style type="text/css">
body{
margin-top:50px;
}
</style>
</head>
<body>
<p>新闻管理系统</p>
<hr />
<table border="0" width="700" height="200">
<tr>
<td width="150"><{$content_title}></td>
<td>
<form action="" method="post" name="myform">
<table border="0" >
<tr>
<td width="150">序号</td>
<td width="150">标题</td>
<td width="150">日期</td>
<td width="150">新闻的id</td>
<td width="150">选择</td>
</tr>
<{section loop=$news name=news}>
<tr>
<td><{$smarty.section.news.iteration}></td>
<td><a href="index.php?action=updatenews&id=<{$news[news].id}>"><{$news[news].title}></a></td>
<td><{$news[news].date}></td>
<td><{$news[news].id}></td>
<td><input type="checkbox" name="checkbox[]" value="<{$news[news].id}>"></td>
</tr>
<{/section}>
</table>
<input type="submit" value="删除">
<input type="hidden" name="action" value="<{$actionvalue}>" >
<input type="hidden" name="action" value="<{$news[news].id}>" >
</form>
</td>
</tr>
<tr>
<td><a href="index.php?action=addnewview" >添加新闻</a></td>
<td>
</td>
</tr>
</table>
</body>
</html>
*.php
<?PHP
include("conn.php");
include("./init.inc.php");
include("./fckeditor/fckeditor.php");
//从php文件分配标量模板变量
//$id=$_REQUEST['id'];
$page_title="新闻管理系统";
$tpl->assign("page_title",$page_title);
//从php文件分配数组到模板
$sql= "SELECT * FROM `news`";
//echo $sql;
$result=$mysqli->query($sql);
$news=array();
while($row=$result->fetch_assoc()){
$news[]=$row;
//转换成索引的数组
}
$tpl->assign("news",$news);
//根据地址栏的参数判断使用的模板
function editor($name,$value){
global $tpl;
$editor=new Fckeditor($name);
$editor -> BasePath='./fckeditor/';
//工具按钮设置
$editor -> ToolbarSet="Default";
//设置它的宽度
$editor -> Width='500px';
//设置它的高度
$editor-> Height='600px';
$editor->value=$value;
$editor->confit['AutoDetecLanguage']=true;
$editor->Confit['DefaultLanguage']='en';
//生成
$fck=$editor->CreateHtml();
$tpl->assign("editor",$fck);
}
$action=$_REQUEST['action'];
switch($action){
case 'addnewview':
$tpl->assign('page_title','添加新闻');
$tpl->assign('content_title','新闻管理登陆');
$tpl->assign('actionvalue','addnews');
//$tpl->assign('actionvalue','updatenews');
editor("content","");
//editor('content','');//调用编辑器,并定义文本域名为content(与下面addnews中的$_REQUEST['content']对应
$tpl->display("addNew.html");
break;
case "addnews":
$content=$_POST['content'];
$title=$_POST['title'];
echo $title;
echo $content;
$sql3="INSERT INTO news(title,content,date) values('{$title}','{$content}',now())";
echo $sql3;
$mysqli->query($sql3);
header("location:index.php");
break;
case "updatenews":
//执行更新操作
$bh=$_REQUEST['id'];
$tpl->assign('page_title','编辑新闻');
$tpl->assign('content_title','管理新闻');
$tpl->assign("id",$bh);
//进行赋值
echo $bh;
//获取要编辑新闻的id
//把新闻分别显示出来
$sql4="select * from news where id='{$bh}'";
$result=$mysqli->query("$sql4");
$rs=$result->fetch_assoc();
echo $rs['title'];
echo $rs['content'];
$tpl->assign("title",$rs['title']);
$tpl->assign('actionvalue','upafter');
//修改之后提交
editor("content",$rs['content']);
$tpl->display("addNew.html");
//调用编辑器,把内容进行赋值
break;
case "upafter":
$bh=$_REQUEST['id'];
echo $bh;
$title=$_REQUEST['title'];
echo $title;
$content=$_REQUEST['content'];
echo $content;
if(isset($_POST['submit'])){
$sql="update news set title='$title',content='$content',date=NOW() where id='{$bh}'";
echo $sql;
$mysqli->query($sql);
}
$tpl->display("index.html");
break;
case "delnews":
$arr=$_POST['checkbox'];
print_r($arr);
for($i=0;$i<count($arr);$i++){
$sql4="delete from news where id='{$arr[$i]}'";
$result=$mysqli->query("$sql4");
echo $sql4.'****';
}
header("location:index.php");
break;
//分配模板变量
//制定模板变量
default:
$tpl->assign("page_title","新闻管理");
$tpl->assign("content_title","新闻管理");
$tpl->assign("actionvalue","delnews");
//$sql="delete * from news where id='{$id}'";
//$result=$mysqli->query($sql);
//$result->fetch_assoc();
//$sql1="select * from news";
//$result=$mysqli->query($sql1);
//while($row=$reuslt->fetch_assoc()){
//$news[]=$row;
//}
$tpl->assign("news",$news);
$tpl->display("index.html");
}
?>
*.html
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title><{$page_title}></title>
<style type="text/css">
body{
margin-top:50px;
}
</style>
</head>
<body>
<p>新闻管理系统</p>
<hr />
<table border="0" width="700" height="200">
<tr>
<td width="150"><{$content_title}></td>
<td>
<form action="" method="post" name="myform">
<table border="0" >
<tr>
<td width="150">序号</td>
<td width="150">标题</td>
<td width="150">日期</td>
<td width="150">新闻的id</td>
<td width="150">选择</td>
</tr>
<{section loop=$news name=news}>
<tr>
<td><{$smarty.section.news.iteration}></td>
<td><a href="index.php?action=updatenews&id=<{$news[news].id}>"><{$news[news].title}></a></td>
<td><{$news[news].date}></td>
<td><{$news[news].id}></td>
<td><input type="checkbox" name="checkbox[]" value="<{$news[news].id}>"></td>
</tr>
<{/section}>
</table>
<input type="submit" value="删除">
<input type="hidden" name="action" value="<{$actionvalue}>" >
<input type="hidden" name="action" value="<{$news[news].id}>" >
</form>
</td>
</tr>
<tr>
<td><a href="index.php?action=addnewview" >添加新闻</a></td>
<td>
</td>
</tr>
</table>
</body>
</html>
相关文章推荐
- PHP程序中使用PDO对象实现对数据库的增删改查操作(PHP+smarty)
- mybatis实战教程(mybatis in action)之三:实现数据的增删改查
- angular js实现增删改查demo(全)
- [Silverlight]WCF RIA Services+Mef+MVVM实现CRUD(增删改查)示例
- java连接mysql数据库 三 实现增删改查操作
- 用C++实现单链表的基本函数以及增删查改
- 在node中使用MonoDB实现增删改查
- PHP实现MYSQL简单的增删改查功能
- C#2005中使用控件DataGridView实现对数据库增删改查操作
- Nutz+jQuery esayUI Datagrid实现增删改查以及分页效果
- 用C#实现对MSSqlServer数据库的增删改查---DAL层
- 顺序表实现增删查改
- web分页显示功能(“小案例:实现web端对客户资源的增删改查”里面的一个功能)
- mybatis实战教程(mybatis in action)之三:实现数据的增删改查
- PHP Smarty 3中实现多语言模板及标签静态化的方法
- 解析smarty模板中类似for的功能实现
- 记录我的第一个用ssh框架开发的web项目——实现简单的登录注册以及增删查改(一)
- 用DTree实现对所有树形结构的增删改查
- mybatis3.2.8注解方式实现数据的增删改查
- MyBatis中SqlSession实现增删改查案例