Ecmall系统自带的分页功能

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Ecmall系统自带的分页功能

2011-06-10

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

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

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';

相关文档
最新文档