在Ecmall的二次开发中,分页是必不可少的。这个系统已经自带了分页功能,下面来看看如何使用这个分页。

下面是一个自定义的类,用于查看订单的详细情况。关键在于get_order_data()这个方法,分页的使用也在这个方法的内部了。应该有的注释都有了,应该会比较容易懂,我不就多说了。

<?php
define('NUM_PER_PAGE', 15); // 每页显示数量 class NowaMagicApp extends MallbaseApp
{
public function index()
{
/* 分页信息 */
$page = $this->_get_page(NUM_PER_PAGE);
$page['item_count'] = $stats['total_count'];
$this->_format_page($page);
$this->assign('page_info', $page); $this->display('gorder.index.html');
} /* 订单记录 */
function orderslog()
{
$goods_id = empty($_GET['id']) ? 0 : intval($_GET['id']);
if (!$goods_id)
{
$this->show_warning('Hacking Attempt');
return;
} $data = $this -> get_order_data($goods_id); if ($data === false)
{
return;
} $this->assign('order', $data); $this->display('gorder.index.html'); } function get_order_data($goods_id)
{
//clean_cache();
$cache_server =& cache_server();
//print_r($cache_server);
$key = 'order_' . $goods_id;
//$key = $this->_get_cache_id();
$r = $cache_server->get($key);
$cached = true; $db = &db(); $sql = "select count(*)
from shop_order a, shop_order_extm b, shop_order_goods c
where a.order_id = b.order_id and b.order_id = c.order_id
and c.goods_id = '".$goods_id."'
and a.status != '11'
and a.status != '0'
and a.status != '20'
order by a.add_time desc ";
//echo $sql;
$num = $db -> getone($sql); //求出总记录数
$page = $this->_get_page(NUM_PER_PAGE); //每页显示的条数,默认是10条
$page['item_count'] = $num; // 返回一个数组$page,$page['limit']=0,10
$this->_format_page($page); //格式化分页 $sql2 = "select a.order_id, a.buyer_name, a.add_time, a.status, b.phone_tel, b.phone_mob, b.consignee, c.price, c.quantity, c.goods_id
from shop_order a, shop_order_extm b, shop_order_goods c
where a.order_id = b.order_id and b.order_id = c.order_id
and c.goods_id = '".$goods_id."'
and a.status != '11'
and a.status != '0'
and a.status != '20'
order by a.add_time desc limit ".$page['limit']; $result = $db -> query($sql2); $this -> assign('page_info',$page); //向模板页传递页数
$this -> assign('que',$sql2); //向模板页传递查询结果 //$r = array();
while($myrow = $db -> fetch_array($result))
{
$r[] = $myrow;
} $cache_server->set($key, $r, 1);
return $r;
} } ?>

 简化如下:

Define("LIMIT",10);
$goods_mod = & db('test');//构建实体模型(操作表)
$count = 'select count(id) from test';
$num = $goods_mod -> getone($count);//求出总记录数 $page = $this->_get_page(LIMIT);//每页显示的条数,默认是10条
$page['item_count'] = $num;// 返回一个数组$page,$page['limit']=0,10
$this->_format_page($page);//格式化分页
$sql = 'select id,title,content from test order by id desc limit '.$page['limit'];
$que = $goods_mod -> getAll($sql);//查询记录
$this -> assign('page_info',$page); //向模板页传递页数
$this -> assign('que',$que); //向模板页传递查询结果

ecmall分页的更多相关文章

  1. Ecmall系统自带的分页功能

    在Ecmall的二次开发中,分页是必不可少的.这个系统已经自带了分页功能,下面来看看如何使用这个分页. 下面是一个自定义的类,用于查看订单的详细情况.关键在于get_order_data()这个方法, ...

  2. ecmall中的分页问题

    <ecmall>Ecmall系统自带的分页功能 在Ecmall的二次开发中,分页是必不可少的.这个系统已经自带了分页功能,下面来看看如何使用这个分页. 下面是一个自定义的类,用于查看订单的 ...

  3. Ecmall系统自带的分页功能使用

    在控制器如果没有定义相关模型,直接使用sql语句的话,直接使用如下语句. 即: public $db; $this->db = &db(); //然后开始使用分页类 $sql='sele ...

  4. 记一次SQLServer的分页优化兼谈谈使用Row_Number()分页存在的问题

    最近有项目反应,在服务器CPU使用较高的时候,我们的事件查询页面非常的慢,查询几条记录竟然要4分钟甚至更长,而且在翻第二页的时候也是要这么多的时间,这肯定是不能接受的,也是让现场用SQLServerP ...

  5. js实现前端分页页码管理

    用JS实现前端分页页码管理,可以很美观的区分页码显示(这也是参考大多数网站的分页页码展示),能够有很好的用户体验,这也是有业务需要就写了一下,还是新手,经验不足,欢迎指出批评! 首先先看效果图: 这是 ...

  6. JdbcTemplate+PageImpl实现多表分页查询

    一.基础实体 @MappedSuperclass public abstract class AbsIdEntity implements Serializable { private static ...

  7. MVC如何使用开源分页插件shenniu.pager.js

    最近比较忙,前期忙公司手机端接口项目,各种开发+调试+发布现在几乎上线无问题了:虽然公司项目忙不过在期间抽空做了两件个人觉得有意义的事情,一者使用aspnetcore开发了个人线上项目(要说线上其实只 ...

  8. NET Core-TagHelper实现分页标签

    这里将要和大家分享的是学习总结使用TagHelper实现分页标签,之前分享过一篇使用HtmlHelper扩展了一个分页写法地址可以点击这里http://www.cnblogs.com/wangrudo ...

  9. 套用JQuery EasyUI列表显示数据、分页、查询

    声明,本博客从csdn搬到cnblogs博客园了,以前的csdn不再更新,朋友们可以到这儿来找我的文章,更多的文章会发表,谢谢关注! 有时候闲的无聊,看到extjs那么肥大,真想把自己的项目改了,最近 ...

随机推荐

  1. tinyxml优化之二

    原文链接:http://www.cnblogs.com/zouzf/p/4216046.html tinyxml优化之一说到了效率在差别有三方面的原因:解析的方式.内存分配(字符串操作).冗余的安全性 ...

  2. Django QuerySet API

    https://docs.djangoproject.com/en/2.1/ref/models/querysets/

  3. Effective C++ 条款10:令operator= 返回一个reference to *this

    class Widget { public: ... Widget& operator+=(const Widget& rhs) // 返回类型是个reference,指向当前对象 { ...

  4. java实现定时任务的三种方法 - 转载

    java实现定时任务的三种方法 /** * 普通thread * 这是最常见的,创建一个thread,然后让它在while循环里一直运行着, * 通过sleep方法来达到定时任务的效果.这样可以快速简 ...

  5. Pandas IO工具

    Pandas I/O API是一套像pd.read_csv()一样返回Pandas对象的顶级读取器函数. 读取文本文件(或平面文件)的两个主要功能是read_csv()和read_table().它们 ...

  6. Java多线程 - 线程同步

    多线程操作同一个对象时,容易引发线程安全问题.为了解决线程安全问题,Java多线程引入了同步监视器. 同步代码块 同步代码块语法格式如下: synchronized(obj){ //此处的代码即为同步 ...

  7. Spring + Spring MVC + MyBatis框架整合

    ---恢复内容开始--- 一.Maven Web项目创建 如有需要,请参考:使用maven创建web项目 二.Spring + Spring MVC + MyBatis整合 1.Maven引入需要的J ...

  8. LeetCode第[21][23]题(Java):Merge Sorted Lists

    题目:合并两个已排序链表 难度:Easy 题目内容: Merge two sorted linked lists and return it as a new list. The new list s ...

  9. linux的文件

    今日感慨:linux根目录下的文件夹含义 bin的知识,二进制文件,其用途依系统或应用而定 . 也就是说,一般来讲是机器代码,汇编语言编译后的结果,(DOS下汇编语言编译后与.com文件相类似),用d ...

  10. Mac系统下安装ipython分别支持python2和python3

    操作系统:Mac10.11.5 python2.7.13 python3.6.1 安装python2: brew install python 安装python3: brew install pyth ...