程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> PHP實現阿裡巴巴實現同類產品翻頁效果

PHP實現阿裡巴巴實現同類產品翻頁效果

編輯:關於PHP編程

當前頁左邊的頁碼為最新的產品,按更新時間呈升序排列;右邊的頁碼為早期的產品, 按更新時間呈降序排列。如果左邊的記錄條數小於$space(頁碼區段)的值,頁碼$start從1開始向右增值。如果左則的記錄條數多於$left(左右各顯示頁數)的值,$start將從左邊記錄數減去$left值開始記數。

Copy to ClipboardLiehuo.Net Codes引用的內容:[www.bkjia.com] 1 <?php
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 = "<a href=\"{$url}\">上一頁</a><ol>";
51 }elseif($c == 1) {
52 $url = $this->pageName."-".$list1[0]['id'].".html";
53 $pages = "<a href=\"{$url}\">上一頁</a><ol>";
54 }else {
55 $pages = "";
56 }
57
58
59 /** 當前頁的左邊內容 **/
60 foreach($list1 as $item) {
61 $url = $this->pageName."-".$item['id'].".html";
62 $pages .= "<li><a href=\"{$url}\">{$start}</a></li>";
63 $start++;
64 }
65
66 $pages .= "<li><b>{$leftCount}</b></li>";
67 $start++;
68
69 /** 當前頁面右邊的內容 **/
70 foreach($list1 as $item) {
71 $url = $this->pageName."-".$item['id'].".html";
72 $pages .= "<li><a href=\"{$url}\">{$start}</a></li>";
73 $start++;
74 }
75
76 /** 下一頁的鏈接 **/
77 $c = count($list2);
78 if($c > 0) {
79 $url = $this->pageName."-".$list2[0]['id'].".html";
80 $pages .= "<a href=\"{$url}\">下一頁</a><ol>";
81 }else {
82 $pages .= "";
83 }
84
85 return $pages;
86 }
87 };
88 ?>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved