在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. 判断一个对象是否有new

    C++语言中,对象没有空和不空的概念,只有对象指针才有空和不空的概念 判断对象指针是否为空只需要和NULL常量进行比较即可 如果相等,则为空,否则不为空 另外对象虽然没有空和不空的概念,但是有有效和无 ...

  2. Merge-Sort(归并排序)

    Merge-Sort(归并排序) 思想 利用分治的思想,具体实现也就是递归,不断的将问题话分为更小的子问题,当子问题中规模为1的时候,认为数组已经有序了,然后再将子问题求得的结果不断的合并.也就是将长 ...

  3. php数组元素去空,测试奇数偶数

    <?php//返回奇数 function test_odd($var) { return($var & 1); } $a1=array("a","b&quo ...

  4. 论Spark高手是怎样炼成的

    SPARK J大数据的处理怎么能变快一点,答案是请用spark,因为它是基于内存的,可以有效减少数据的落地次数.Spark性能超过Hadoop百倍,从多迭代批量处理出发,兼收并蓄数据仓库.流处理和图计 ...

  5. numpy 矩阵归一化

    new_value = (value - min)/(max-min) def normalization(datingDatamat): max_arr = datingDatamat.max(ax ...

  6. Prism开发人员指南5-WPF开发 Developer's Guide to Microsoft Prism Library 5.0 for WPF (英汉对照版)

    April 2014 2014四月   Prism provides guidance in the form of samples and documentation that help you e ...

  7. LeetCode OJ:Maximum Product Subarray(子数组最大乘积)

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  8. java中的策略设计模式

    本文主要讲java中的策略模式:一个可以根据不同的传入参数而具有不同行为的方法,就叫策略模式.概念可能有点不好理解,具体看下面代码: import java.util.Arrays; /** * 策略 ...

  9. PostgreSQL 日常SQL记录

    平时用的比较多的SQL语句,有时候会忘掉一点点,在这里记录一下: 1.创建表的同时,插入数据: create table test as select generate_series(1, 10000 ...

  10. padding和margin的用法

    在CSS中margin是指从自身边框到另一个容器边框之间的距离,就是容器外距离.在CSS中padding是指自身边框到自身内部另一个容器边框之间的距离,就是容器内距离. 一.padding 1.语法结 ...