首页 > php教程 > php手册 > 正文

PHP实现阿里巴巴实现同类产品翻页效果

WBOY
发布: 2016-06-13 11:37:31
原创
1379 人浏览过

当前页左边的页码为最新的产品,按更新时间呈升序排列;右边的页码为早期的产品, 按更新时间呈降序排列。如果左边的记录条数小于$space(页码区段)的值,页码$start从1开始向右增值。如果左则的记录条数多于$left(左右各显示页数)的值,$start将从左边记录数减去$left值开始记数。

Copy to Clipboard引用的内容:[www.bkjia.com] 1 2 /**实现同类产品翻页 **/
3
4
5 class pager
6 {
7 protected $space;
8 protected $left;
9 protected $DB;
10 protected $pageName;
11
12 public function setSpace($num) {
13 $this->space = $num;
14 $this->left = ceil(($num-1)/2);
15 }
16
17 public function setDB(&$db) {
18 $this->DB = $db;
19 }
20
21 public function setPageName($pageName) {
22 $this->pageName = $pageName;
23 }
24
25 public function getPages($catid, $exptime) {
26 $fields = array("`id`,`title`");
27 $left = array(">" => array("exptime"=>$exptime), "memberid" => gs(_MEM_PREFIX_ . "memberid"), "catid"=>$catid);
28 $right = array("<" => array("exptime"=>$exptime), "memberid" => gs(_MEM_PREFIX_ . "memberid"), "catid"=>$catid);
29
30 $leftCount = $this->DB->getCount($left);
31
32 if($leftCount <= $this->left) {
33 $star = 1;
34 $leftLimit = "LIMIT" . $leftCount;
35 $rightLimit = "LIMIT " . ($this->space-$leftCount);
36 }
37 else {
38 $start = $leftCount - $this->left;
39 $leftLimit = "LIMIT " . $this->left;
40 $rightLimit = $leftLimit;
41 }
42
43 $list1 = $this->DB->findAll($left, array("exptime"=>"ASC"), $leftLimit, $fields);
44 $list2 = $this->DB->findAll($right, array("exptime"=>"DESC"), $rightLimit, $fields);
45
46 /**上一页链接 **/
47 $c = count($list1);
48 if($c > 1) {
49 $url = $this->pageName."-".$list1[$c]['id'].".html";
50 $pages = "上一页
    ";
    51 }elseif($c == 1) {
    52 $url = $this->pageName."-".$list1[0]['id'].".html";
    53 $pages = "上一页
      ";
      54 }else {
      55 $pages = "";
      56 }
      57
      58
      59 /**当前页的左边内容 **/
      60 foreach($list1 as $item) {
      61 $url = $this->pageName."-".$item['id'].".html";
      62 $pages .= "
    1. {$start}
    2. ";
      63 $start ;
      64 }
      65
      66 $pages .= "
    3. {$leftCount}
    4. ";
      67 $start ;
      68
      69 /**当前页面右边的内容 **/
      70 foreach($list1 as $item) {
      71 $url = $this->pageName."-".$item['id'].".html";
      72 $pages .= "
    5. {$start}
    6. ";
      73 $start ;
      74 }
      75
      76 /**下一页的链接 **/
      77 $c = count($list2);
      78 if($c > 0) {
      79 $url = $this->pageName."-".$list2[0]['id'].".html";
      80 $pages .= "下一页
        ";
        81 }else {
        82 $pages .= "";
        83 }
        84
        85 return $pages;
        86 }
        87 };
        88 ?>
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板