smarty分页
来源:互联网 发布:it域名注册 编辑:程序博客网 时间:2024/04/30 06:09
index.php
<?php
include "./libs/Smarty.class.php";
require("page_class.php");
require("mydb_class.php");
$tpl = new Smarty();
$tpl->template_dir = "./templates/";
$tpl->compile_dir = "./templates_c/";
$tpl->cache_dir = "./cache/";
$tpl->caching=false;
$tpl->cache_lifetime=60*60*4;
$tpl->left_delimiter = '<{';
$tpl->right_delimiter = '}>';
$current_page=isset($_GET['page'])?intval($_GET['page']):1;
if(!$tpl->is_cached("index.tpl", $current_page)) {
$mydb=new MyDB();
$total=$mydb->getRowTotal();
$fpage=new Page($total,$current_page, 5);
$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.tpl", $current_page);
?>
mydb_class.php
<?php
include "./libs/Smarty.class.php";
require("page_class.php");
require("mydb_class.php");
$tpl = new Smarty();
$tpl->template_dir = "./templates/";
$tpl->compile_dir = "./templates_c/";
$tpl->cache_dir = "./cache/";
$tpl->caching=false;
$tpl->cache_lifetime=60*60*4;
$tpl->left_delimiter = '<{';
$tpl->right_delimiter = '}>';
$current_page=isset($_GET['page'])?intval($_GET['page']):1;
if(!$tpl->is_cached("index.tpl", $current_page)) {
$mydb=new MyDB();
$total=$mydb->getRowTotal();
$fpage=new Page($total,$current_page, 5);
$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.tpl", $current_page);
?>
index.tpl
<html>
<head><title> Smarty实现商品列表 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<{* 以表格的形式显式当前页的特定个数数据 *}>
<table align="center" border="1" width="90%">
<caption><h1> <{ $tableName }> </h1></caption>
<tr>
<th>编号</th> <th>商品名称</th> <th>价格</th> <th>商品介绍</th>
</tr>
<{* 使用section语句遍历从PHP中分配过来的商品数组$products *}>
<{ section name=record loop=$products }>
<tr>
<td> <{ $products[record].productID }> </td>
<td> <{ $products[record].name }> </td>
<td> <{ $products[record].price }> </td>
<td> <{ $products[record].description }> </td>
</tr>
<{ sectionelse }>
<tr><td colspan=4> 没有任何商品存在 </td></tr>
<{ /section }>
</table>
<{* 在下面段落中输出和分页有关的信息,并输出用户可以页面切换操作的链接 *}>
<p align="center">
共<b> <{ $pageInfo.row_total }> </b>条记录,
显示第 <b> <{ $pageInfo.page_start }> </b>-<b> <{ $pageInfo.page_end }> </b> 条记录
<a href='<{ $url }>?page=1'>|<</a>
<{ if $pageInfo.prev_page }>
<a href='<{ $url }>?page=<{ $pageInfo.prev_page }>'><<</a>
<{ else }>
<<
<{ /if }>
<{ if $pageInfo.next_page }>
<a href='<{ $url }>?page=<{ $pageInfo.next_page }>'>>></a>
<{ else }>
>>
<{ /if }>
<a href='<{ $url }>?page=<{ $pageInfo.page_num }>'>>|</a>
当前<b> <{ $pageInfo.current_page }>/<{ $pageInfo.page_num }> </b>页
</p>
</body>
</html>
- smarty分页
- smarty分页
- smarty分页
- smarty分页
- Smarty的分页实现
- Smarty的分页实现
- 分页函数(Smarty + Adodb)
- Smarty的分页实现
- smarty的简单分页
- SMARTY分页详解
- smarty的简单分页
- SMARTY分页详解
- smarty的简单分页
- SMARTY分页插件
- 应用smarty分页
- smarty商品分页
- smarty实现分页
- smarty实现分页代码
- v$sysstat表解释
- SQL Server 2000服务无法启动,提示“系统找不到指定的文件”解决方法及sp4安装不上
- smarty局部缓存
- fla文件与as文件之间的绑定
- QT国际化支持
- smarty分页
- RAID卡原理与设置
- 删除MySQL二进制日志的3种方法
- 如何优化sql语句
- 显示动态动画
- 字符串常量下标引用
- 烧写busybox的方法(烧写到3560e芯片的盒子中)
- 研一的苦恼
- 初始化块