<ecmall>Ecmall系统自带的分页功能

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

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

01<?php 
02define('NUM_PER_PAGE', 15);        // 每页显示数量 
03  
04classNowaMagicApp extendsMallbaseApp   
05{   
06    publicfunctionindex()   
07    { 
08        /* 分页信息 */
09        $page= $this->_get_page(NUM_PER_PAGE); 
10        $page['item_count'] = $stats['total_count']; 
11        $this->_format_page($page); 
12        $this->assign('page_info', $page); 
13  
14        $this->display('gorder.index.html');    
15    }   
16      
17    /* 订单记录 */
18    functionorderslog() 
19    { 
20        $goods_id= empty($_GET['id']) ? 0 : intval($_GET['id']); 
21        if(!$goods_id) 
22        { 
23            $this->show_warning('Hacking Attempt'); 
24            return; 
25        } 
26          
27        $data= $this-> get_order_data($goods_id); 
28          
29        if($data=== false) 
30        { 
31            return; 
32        } 
33          
34        $this->assign('order', $data); 
35  
36        $this->display('gorder.index.html'); 
37  
38    } 
39      
40    functionget_order_data($goods_id) 
41    { 
42        //clean_cache(); 
43        $cache_server=& cache_server(); 
44        //print_r($cache_server); 
45        $key= 'order_'. $goods_id; 
46        //$key = $this->_get_cache_id(); 
47        $r= $cache_server->get($key); 
48        $cached= true; 
49          
50        $db= &db(); 
51          
52        $sql= "select count(*) 
53                from shop_order a, shop_order_extm b, shop_order_goods c 
54                where a.order_id = b.order_id andb.order_id = c.order_id 
55                andc.goods_id = '".$goods_id."'
56                anda.status != '11'
57                anda.status != '0'
58                anda.status != '20'
59                order by a.add_time desc "; 
60        //echo $sql; 
61        $num= $db-> getone($sql);              //求出总记录数 
62        $page= $this->_get_page(NUM_PER_PAGE);  //每页显示的条数,默认是10条 
63        $page['item_count'] = $num;             // 返回一个数组$page,$page['limit']=0,10 
64        $this->_format_page($page);              //格式化分页 
65          
66        $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  
67                from shop_order a, shop_order_extm b, shop_order_goods c 
68                where a.order_id = b.order_id andb.order_id = c.order_id 
69                andc.goods_id = '".$goods_id."'
70                anda.status != '11'
71                anda.status != '0'
72                anda.status != '20'
73                order by a.add_time desc limit ".$page['limit']; 
74          
75        $result= $db-> query($sql2); 
76          
77        $this-> assign('page_info',$page);  //向模板页传递页数 
78        $this-> assign('que',$sql2);    //向模板页传递查询结果 
79          
80        //$r = array(); 
81        while($myrow= $db-> fetch_array($result)) 
82        { 
83            $r[] = $myrow; 
84        } 
85  
86        $cache_server->set($key, $r, 1); 
87        return$r; 
88    } 
89      
90} 
91  
92?>

简化如下:

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. tp中使用分页技术

    1 public function showList() { $m_ld = D ( 'guangxi_ld' ); $page = I ( 'get.p', 1 ); // 在配置中获取分页值 $p ...

  2. Oracle中经典分页代码!

    在Oracle中因为没有top关键字,所以在sqlserver中的分页代码并不适用于Oracle,那么在Oracle中如何来实现分页呢? --查询所有数据 STUNO STUNAME STUAGE S ...

  3. 在yii中使用分页

    yii中使用分页很方便,如下两种方法: 在控制器中: 1. $criteria = new CDbCriteria(); //new cdbcriteria数据库$criteria->id = ...

  4. [数据库]Oracle和mysql中的分页总结

    Mysql中的分页 物理分页 •在sql查询时,从数据库只检索分页需要的数据 •通常不同的数据库有着不同的物理分页语句 •mysql物理分页,采用limit关键字 •例如:检索11-20条 selec ...

  5. LigerUi中的Grid中不分页显示(local)!

    LigerUi中的Grid中不分页显示! grid为local usePager: true,                         //是否分页

  6. mongo中的分页查询

    /** * @param $uid * @param $app_id * @param $start_time * @param $end_time * @param $start_page * @p ...

  7. springboot中使用分页,文件上传,jquery的具体步骤(持续更新)

    分页: pom.xml     加依赖 <dependency> <groupId>com.github.pagehelper</groupId> <arti ...

  8. restful中的分页

    普通分页 普通分页类似于Django中的分页 源码 class PageNumberPagination(BasePagination): """ A simple pa ...

  9. jdbcTemplate 后台接口中的分页

    Springboot+jdbcTemplate  对查询结果列表做分页, 之前开发的小项目,数据逐渐增多,每次返回所有的查询结果,耗费性能和时间 想到做分页. 于是从简单的分页做起. jdbcTemp ...

随机推荐

  1. 流量分析系统----实现-echarts模拟迁移(bmap.js/china.js)

    china.js: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  2. Boostrap常用组件英文名

    dropdownlisttabsearchVertical TabSidebar with tabssidebarExpandable Panel ListFiltered Attendees Lis ...

  3. 获取文件的MD5值,比较两个文件是否完全相同

    代码: public class MD5Test { public static void main(String[] args) { String s1 = MD5Test.MD5Operation ...

  4. Python学习进程(7)字符串

        本节介绍字符串的创建与操作方法.     (1)创建字符串:     创建字符串既可以用单引号也可以用双引号: root@SJM:/home/sunjimeng/桌面# cat text.py ...

  5. Python学习进程(2)Python环境的搭建

        本节主要介绍在windows和Linux平台上如何搭建Python编程环境.     (1)查看Python版本: windows: C:\Users\JMSun>python 'pyt ...

  6. python配置文件操作

    步骤: 1.导入模块  import configparser 2.创建实例 cf = configparser.ConfigParser() 3.读取配置文件,若配置文件中有中文,则需设置编码格式  ...

  7. samtools使用过程中出现的问题

    1.EOP marker is absent 在使用samtools index时出现 EOF是指the end of file,即samtools认为你的bam文件是不完整的. 如果把view参数的 ...

  8. readonly与disabled

    readonly与disabled都能将元素设为不可编辑状态,但他们有许多区别: 1.样式 readonly与一般样式一样,disabled会将元素背景设为灰色 2.应用范围 readonly只对in ...

  9. INSPIRED启示录 读书笔记 - 第9章 产品副经理

    发现帮手 从本质上讲,产品就是创意,产品经理的职责是想出好点并加以实现.我们需要好点子,有些想法是我们自己的创意,但如果仅依靠自己,就会严重限制创意的发挥 做产品要找公司最聪明的人合作,发现公司里潜在 ...

  10. K8s 日常操作

    1.获取所有Pods kubectl get pods --namespace=default 2.获取所有Deployments kubectl get deployments --namespac ...