Pagination class, php pagination class _ PHP Tutorial

Source: Internet
Author: User
Paging class: php paging class. Paging class, php paging class page. class. php1? Php2 * 3 * PHP paging class 4 * @ packagePage5 * @ Created2013-03-276 * @ Modify2013-03-277 * @ linkwww.60ie. net8 * Example: 9 paging class, php paging class

Page. class. php

1
 GetPagerContent (); 11 echo $ pageStr; 12 */13 class Pager {14 private $ pageSize = 10; 15 private $ pageIndex; // page number 16 private $ totalNum; // total data 17 18 private $ totalPagesCount; // total number of pages 19 20 private $ pageUrl; // 21 private static $ _ instance; 22 23 public function _ construct ($ p_totalNum, $ p_pageIndex, $ p_pageSize = 10, $ p_initNum = 3, $ p_initMaxNum = 5) {24 if (! Isset ($ p_totalNum) |! Isset ($ p_pageIndex) {25 die ("pager initial error"); 26} 27 28 $ this-> totalNum = $ p_totalNum; // total data 29 $ this-> pageIndex = $ p_pageIndex; 30 $ this-> pageSize = $ p_pageSize; 31 $ this-> initNum = $ p_initNum; 32 $ this-> initMaxNum = $ p_initMaxNum; 33 $ this-> totalPagesCount = ceil ($ p_totalNum/$ p_pageSize ); 34 $ this-> pageUrl = $ this-> _ getPageUrl (); 35 36 $ this-> _ initPagerLegal (); 37} 38 39 40/** 41 * get removed The current URL String 42*43 * @ return String URL String 44 */45 private function _ getPageUrl () {46 $ CurrentUrl = $ _ SERVER ["REQUEST_URI"]; // Retrieve URI 47 $ arrUrl = parse_url ($ CurrentUrl); // Parse the URI and return an Associated array 48 $ urlQuery = $ arrUrl ["query"]; // obtain the value of the array key as query 49 // Convert "?" in the URI Page = page number "is replaced by"? Page "50 if ($ urlQuery) {51 // $ urlQuery = preg_replace ("/(^ | &) page = ". $ this-> pageIndex. "/", "", $ urlQuery); 52 $ urlQuery = ""; 53 $ CurrentUrl = str_replace ($ arrUrl ["query"], $ urlQuery, $ CurrentUrl ); 54 echo $ CurrentUrl; 55 if ($ urlQuery) {56 $ CurrentUrl. = "& page"; 57} else {58 $ CurrentUrl. = "page"; 59} 60} else {61 $ CurrentUrl. = "? Page "; 62} 63 64 return $ CurrentUrl; 65 66} 67/* 68 * Set the validity of page parameters 69 * @ return void 70 */71 private function _ initPagerLegal () 72 {73 // when the page number is invalid, modify the page number 74 if ((! Is_numeric ($ this-> pageIndex) | $ this-> pageIndex <1) 75 {76 $ this-> pageIndex = 1; 77} elseif ($ this-> pageIndex> $ this-> totalPagesCount) 78 {79 $ this-> pageIndex = $ this-> totalPagesCount; 80} 81} 82 83 public function GetPagerContent () {84 $ str ="

"; 85 // homepage previous page 86/* if ($ this-> pageIndex = 1) 87 {88 $ str. = "homepage ". "\ n"; 89 $ str. = "previous page ". "\ n ". "\ n"; 90} else 91 {92 $ str. = "pageUrl} = 1 'class = 'tids' title = 'homepage'> homepage ". "\ n"; 93 $ str. = "pageUrl} = ". ($ this-> pageIndex-1 ). "'class = 'tids' title = 'preput'> Previous Page ". "\ n ". "\ n"; 94} 95 */96 if ($ this-> pageIndex! = 1) {97 $ str. = "$ this-> pageUrl} = 1 'class = 'tids' title = 'homepage'> homepage ". "\ n"; 98 $ str. = "$ this-> pageUrl} = ". ($ this-> pageIndex-1 ). "'class = 'tids' title = 'preput'> Previous Page ". "\ n ". "\ n"; 99} 100/* 101 102 except for the first and last page paging logic 103 104 */105 // 106 $ currnt = "" under 10 pages (inclusive ""; 107 if ($ this-> totalPagesCount <= 10) 108 {109 110 for ($ I = 1; $ I <= $ this-> totalPagesCount; $ I ++) 111 112 {113 if ($ I ==$ this-> pageIndex) 114 {$ currnt = "class = 'current'";} 11 5 else 116 {$ currnt = "";} 117 $ str. = "$ this-> pageUrl }={$ I} '{$ currnt}> $ I ". "\ n"; 118} 119} else // over 10 pages 120 {if ($ this-> pageIndex <3) // the current page is less than 3 121 {122 for ($ I = 1; $ I <= 3; $ I ++) 123 {124 if ($ I ==$ this-> pageIndex) 125 {$ currnt = "class = 'current'";} 126 else 127 {$ currnt = "";} 128 $ str. = "$ this-> pageUrl }={$ I} '{$ currnt}> $ I ". "\ n"; 129} 130 $ str. = "...... ". "\ N"; 132 133 for ($ I = $ this-> totalPagesCount-3 + 1; $ I <= $ this-> totalPagesCount; $ I ++) // Function 1 134 {135 $ str. = "$ this-> pageUrl }={$ I} '> $ I ". & quot; \ n & quot; 136 137} 138} elseif ($ this-> pageIndex <= 5) // 5 >= current page >=3 139 {140 for ($ I = 1; $ I <= ($ this-> pageIndex + 1); $ I ++) 141 {142 if ($ I ==$ this-> pageIndex) 143 {$ currnt = "class = 'current'";} 144 else 145 {$ currnt = "";} 146 $ str. = "$ this-> pageUrl }={$ I} '{$ currnt}> $ I ". "\ n"; 147 148} 149 $ str. = "...... ". "\ N"; 150 151 for ($ I = $ this-> totalPagesCount-3 + 1; $ I <= $ this-> totalPagesCount; $ I ++) // Function 1 152 {153 $ str. = "$ this-> pageUrl }={$ I} '> $ I ". "\ n"; 154 155} 156 157} elseif (5 <$ this-> pageIndex & $ this-> pageIndex <= $ this-> totalPagesCount-5) // the current page is greater than 5 and smaller than the total number of pages-5158 159 160 {161 for ($ I = 1; $ I <= 3; $ I ++) 162 {163 $ str. = "$ this-> pageUrl }={$ I} '> $ I ". & quot; \ n & quot; 164} 165 $ str. = "...... "; 166 for ($ I = $ this-> pageIndex-1; $ I <= $ this-> pageIndex + 1 & $ I <= $ this-> totalPagesCount-5 + 1; $ I ++) 167 {168 if ($ I ==$ this-> pageIndex) 169 {$ currnt = "class = 'current '";} 170 else 171 {$ currnt = "";} 172 $ str. = "$ this-> pageUrl }={$ I} '{$ currnt}> $ I ". & quot; \ n & quot; 173} 174 $ str. = "...... "; 175 176 for ($ I = $ this-> totalPagesCount-3 + 1; $ I <= $ this-> totalPagesCount; $ I ++) 177 {178 $ str. = "$ this-> pageUrl }={$ I} '> $ I ". "\ n"; 179 180} 181} else 182 {183 184 for ($ I = 1; $ I <= 3; $ I ++) 185 {186 $ str. = "$ this-> pageUrl }={$ I} '> $ I ". & quot; \ n & quot; 187} 188 $ str. = "...... ". "\ N"; 189 190 for ($ I = $ this-> totalPagesCount-5; $ I <= $ this-> totalPagesCount; $ I ++) // Function 1 191 {192 if ($ I ==$ this-> pageIndex) 193 {$ currnt = "class = 'current '";} 194 else 195 {$ currnt = "";} 196 $ str. = "$ this-> pageUrl }={$ I} '{$ currnt}> $ I ". "\ n "; 197 198} 199 200 201 202 203 204/* 205 206 after the beginning and end of the page, the page logic ends at 207 208 */209 210/211/* if ($ this-> pageIndex = $ this-> totalPagesCount) 214 {215 $ str. = "\ N ". "next page ". "\ n"; 216 $ str. = "Last Page ". "\ n"; 217} else 218 {219 $ str. = "\ n ". "pageUrl} = ". ($ this-> pageIndex + 1 ). "'class = 'tids' title = 'next page'> next page ". "\ n"; 220 $ str. = "pageUrl }={$ this-> totalPagesCount} 'class = 'tids' title = 'Last page'> last page ". & quot; \ n & quot; 221} 222 */223 if ($ this-> pageIndex! = $ This-> totalPagesCount) {224 $ str. = "\ n ". "$ this-> pageUrl} = ". ($ this-> pageIndex + 1 ). "'class = 'tids' title = 'next page'> next page ". "\ n"; 225 $ str. = "$ this-> pageUrl }={$ this-> totalPagesCount} 'class = 'tids' title = 'Last page'> last page ". & quot; \ n & quot; 226} 227 $ str. ="

"; 228 return $ str; 229} 230 231 232 233/** 234 * get instance 235 * @ return 236 */237 // static public function getInstance () {239 // if (is_null (self: $ _ instance) {240 // self: $ _ instance = new pager (); 241 //} 242 // return self: $ _ instance; 243 //} 244 245 246} 247?>

Implementation class page. php

12
 3---- Paging demonstration -----4
 567
 GetPagerContent (); 12 echo $ pageStr; 13?> 1415   

Style settings

1 body, html {padding: 0px; margin: 0px; color: #333333; font-family: "", Arial, Lucida, Verdana, Helvetica, sans-serif; font-size: 12px; line-height: 150%;} 2 3 h1, h2, h3, h4, h5, h6, ul, li, dl, dt, dd, form, img, p, label {margin: 0; padding: 0; border: none; list-style-type: none ;} 4 5/** front-end paging style **/6 7. pagination {margin: 10px 0 0; padding: 5px 0; text-align: rightright; height: 20px; line-height: 20px; font-family: Arial, Helvetica, sans-serif, "";} 8 9. pagination a {margin-left: 2px; padding: 2px 7px 2px;} 10 11. pagination. dot {border: medium none; padding: 4px 8px} 12 13. pagination a: link ,. pagination a: visited {border: 1px solid # dedede; color: #696969; text-decoration: none;} 14 15. pagination a: hover ,. pagination a: active ,. pagination. current: link ,. pagination. current: visited {border: 1px solid # dedede; color: # fff; background-color: # ff6600; background-image: none; border: # ff6600 solid 1px;} 16 17. pagination. selectBar {border: # dedede solid 1px; font-size: 12px; width: 95px; height: 21px; line-height: 21px; margin-left: 10px; display: inline} 18 19. pagination. tips {_ padding: 4px 7px 1px ;}

Effect

Huge page. class. php 1? Php 2/* 3 * PHP paging class 4 * @ package Page 5 * @ Created 2013-03-27 6 * @ Modify 2013-03-27 7 * @ link http://www.60ie.net 8 * Example: 9...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.