下面是一个自定义的类,用于查看订单的详细情况。关键在于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); //向模板页传递查询结果