下面是一個自定義的類,用於查看訂單的詳細狀況。關鍵在於get_order_data()這個方法,分頁的使用也在這個方法的內部了。應該有的註釋都有了,應該會比較容易懂,我不就多說了。 html
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); //向模板頁傳遞查詢結果