今天写的程序………………此处省略好多字吧,难以言表…………
*.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>