欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-06-05 12:46:04
...
当前页左边的页码为最新的产品,按更新时间呈升序排列;右边的页码为早期的产品, 按更新时间呈降序排列。如果左边的记录条数小于$space(页码区段)的值,页码$start从1开始向右增值。如果左则的记录条数多于$left(左右各显示页数)的值,$start将从左边记录数减去$left值开始记数。 Copy to ClipboardPHP实现阿里巴巴实现同类产品翻页效果_PHP教程引用的内容:[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 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 ?>

        www.bkjia.comtruehttp://www.bkjia.com/PHPjc/364468.htmlTechArticle当前页左边的页码为最新的产品,按更新时间呈升序排列;右边的页码为早期的产品, 按更新时间呈降序排列。如果左边的记录条数小于...