session_start();
include("./conn.php");
include("./init.inc.php");
include("page_class.php");
include("./FCKeditor/fckeditor.php");
通过html或tpl文件传来的$action通过switch判断:
$action=$_REQUEST['action'];
switch ($action){
//增加新闻:
case "addnewsview":
$tpl->assign("type",$type);
$tpl->assign("content_title","添加新闻管理");
$tpl->assign("page_title","添加新闻");
editor("content","");
$tpl->assign("actionvalue","addnews");
$tpl->display("addnews.html");
break;
case "addnews":
$title=$_REQUEST['title'];
$content=$_REQUEST['content'];
$button=$_REQUEST['Submit'];
if(empty($title) || empty($content)){
echo "请填写完成!";
}else{
$sql="insert into news(author,title,content,date) values('admin','$title','$content',NOW())";
//echo $sql;
$mysqli->query($sql);
//echo $sql;
echo "操作成功!";
}
break;
//修改新闻:
case "editnewsview":
$id=$_REQUEST['id'];
$tpl->assign("type",$type);
$tpl->assign("content_title","添加新闻管理");
$tpl->assign("page_title","添加新闻");
//editor("content","");
$tpl->assign("actionvalue","editnews");
$sql="select * from news where id='{$id}'";
$result=$mysqli->query($sql);
$row=$result->fetch_assoc();
editor("content",$row['content']);
$tpl->assign("title",$row['title']);
$tpl->display("addnews.html");
break;
case "editnews":
$title=$_REQUEST['title'];
$content=$_REQUEST['content'];
$id=$_REQUEST['id'];
$button=$_REQUEST['submit'];
if ($button=='提交'){
$sql="update news set title='$title',content='$content',date=NOW() where id=$id";
//echo $sql;
$mysqli->query($sql);
echo "操作成功!";
}
break;
//删除新闻:
case delete:
//echo "aaaa";
if ($checkbox!="" or count($checkbox)!=0) {
for ($i=0;$i
$result=$mysqli->query("delete from news where id='$checkbox[$i]'");
}
echo "删除成功!";
}
//header("location:./index.php?type={$type}");
break;
default:
//为删除传action值
// $tpl->assign("actionvalue","delete");
//从PHP文件分配标量模板变量:
$page_title="新闻管理系统";
$tpl->assign("page_title",$page_title);
////新闻分页:
$current_page=isset($_GET['page'])?intval($_GET['page']):1;
echo $pageInfo["row_offset"];
class MyDB{
public function getRowTotal(){
global $mysqli;
$result=$mysqli->query("select * from news");
return $result->num_rows;
}
public function getPageRows($offset, $num){
global $mysqli;
$query="SELECT * FROM news ORDER BY id LIMIT $offset, $num";
//echo $query;
if($result=$mysqli->query($query)){
while($row=$result->fetch_assoc())
$allProduct[]=$row;
$result->close();
return $allProduct;
}else{
return FALSE;
}
}
}
if(!$tpl->is_cached("index.html", $current_page)) {
$mydb=new MyDB();
$total=$mydb->getRowTotal();
$fpage=new Page($total,$current_page, 4);
$pageInfo=$fpage->getPageInfo();
$products=$mydb->getPageRows($pageInfo["row_offset"], $pageInfo["row_num"]);
if($products) {
$tpl->assign("tableName", "商品列表");
$tpl->assign("url", "index.php");
$tpl->assign("products", $products);
$tpl->assign("pageInfo", $pageInfo);
}else {
echo "数据读取失败!";
exit;
}
}
$tpl->display("index.html",$current_page);
}