smarty的switch实用
来源:互联网 发布:mac截图保存在哪儿 编辑:程序博客网 时间:2024/04/29 14:38
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 "请填写完成!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php?action=addnewsview\">";
}else{
$sql="insert into news(author,title,content,date) values('admin','$title','$content',NOW())";
//echo $sql;
$mysqli->query($sql);
//echo $sql;
echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php?type={$type}\">";
}
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 "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php?type={$type}\">";
}
break;
//删除新闻:
case delete:
//echo "aaaa";
if ($checkbox!="" or count($checkbox)!=0) {
for ($i=0;$i<count($checkbox);$i++){
$result=$mysqli->query("delete from news where id='$checkbox[$i]'");
}
echo "删除成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";
}
//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);
}
- smarty的switch实用
- [33期] 我写的smarty的插件.代码只有两行.很实用的
- 什么是smarty,Smarty的优点?
- 枚举类型特别实用的特性(在switch语句内使用)
- 枚举类型特别实用的特性(在switch语句内使用)
- 枚举类型特别实用的特性(在switch语句内使用)
- smarty 的注意事项和smarty的安装
- Smarty中文手册,Smarty教程,Smarty模板的入门教材
- Smarty中文手册,Smarty教程,Smarty模板的入门教材
- Smarty的基本配置【smarty.inc.php】
- 【smarty】smarty保留变量的使用
- Smarty入门教程一----Smarty的安装
- 【Smarty】Smarty的下载、配置与Helloworld
- smarty的程序设计部分
- Smarty的分页实现
- Smarty的分页实现
- Smarty的分页实现
- smarty 的判断符号
- Nim取子游戏 (SG函数)
- 上传到Android文件乱码问题
- QT信号与糟机制介绍
- build boost_1_48 on ubuntu and windows
- animation的xml定义中的android:interpolator属性
- smarty的switch实用
- 对android的Activity切换时输入法不弹出来的解决办法
- 我的创新成长之路(一)
- Flash Player 10 中的RTMFP协议(实现P2P技术)
- C&C++编译过程理解
- [光驱、u盘、移动硬盘][引导][分区][PE][系统]相关资料
- IAR Embeded Workbench IDE(CC2430)汇编语言
- System.Data.Odbc.OdbcException (0x80131937): ERROR [IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认
- C程序编译执行过程