The page numbers on the left of the current page are the latest products, arranged in ascending order by update time; the page numbers on the right are earlier products, arranged in descending order by update time. If the number of records on the left is less than the value of $space (page number section), the page number $start increases from 1 to the right. If the number of records on the left is more than the value of $left (the number of pages displayed on the left and right), $start will start counting by subtracting the $left value from the number of records on the left.
Copy to ClipboardQuoted content:
[www.bkjia.com]
1 2 /**Realize page turning of similar products **/
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 /**Previous page link **/
47 $c = count($list1);
48 if($c > 1) {
49 $url = $this->pageName."-".$list1[$c] ['id'].".html";
50 $pages = "
Previous page";
51 }elseif($c == 1) {
52 $url = $this->pageName."-".$list1[0]['id'].".html";
53 $pages = "Previous page";
54 }else {
55 $pages = "";
56 }
57
58
59 /**Content on the left of the current page **/
60 foreach($list1 as $item) {
61 $url = $this->pageName."- ".$item['id'].".html";
62 $pages .= "- {$start}
";
63 $start++;
64 }
65
66 $pages .= "- {$leftCount}< ;/li>";
67 $start++;
68
69 /**Content on the right side of the current page **/
70 foreach($list1 as $item) {
71 $url = $ this->pageName."-".$item['id'].".html";
72 $pages .= " - { $start}
";
73 $start++;
74 }
75
76 /**Link to next page **/
77 $c = count($list2);
78 if($c > 0) {
79 $url = $this->pageName."-".$list2[0]['id'].". html";
80 $pages .= "Next page";
81 }else {
82 $pages .= "";
83 }
84
85 return $pages;
86 }
87 };
88 ?>
http://www.bkjia.com/PHPjc/364468.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364468.htmlTechArticleThe page numbers on the left of the current page are the latest products, arranged in ascending order by update time; the page numbers on the right are earlier products , arranged in descending order by update time. If the number of records on the left is less than...