PHP custom pagination class complete instance,
The example in this article describes the PHP custom paging class. Share to everyone for your reference, as follows:
<?phpheader ("content-type:text/html; Charset=utf-8 "), class subpages{private $each _disnums;//The number of entries per page private $nums;//Total number of entries private $current _page;//currently selected page Private $sub _pages;//The number of pages per display private $pageNums;//The total number of pages private $page _array = Array ();//the array to construct the paging private $subPage _link;// Each paging link//private $subPage _type;//displays the type of paging/* When @subpage_type=1 is normal paging mode example: A total of 4,523 records, 10 per page, current 1th/453 page [first] [prev] [Next Page] [Last] when @subpage_type=2 for the classic page style example: Current 1th/453 page [first] [prev] 1 2 3 4 5 6 7 8 9 10 [next] [last] */function __constru CT ($each _disnums, $nums, $current _page, $sub _pages, $subPage _link) {$this->each_disnums=intval ($each _disnums); $ This->nums=intval ($nums); if (! $current _page) {$this->current_page=1;} else{$this->current_page=intval ($current _page); } $this->sub_pages=intval ($sub _pages); $this->pagenums=ceil ($nums/$each _disnums); $this->subpage_link= $subPage _link; $this->show_subpages ($subPage _type); }//The Show_subpages function is used inside the constructor. And it's used to judge what the page is showing./* Function SHow_subpages ($subPage _type) {if ($subPage _type = = 1) {$this->subpagecss1 (); }else if ($subPage _type = = 2) {$this->subpagecss2 (); }}*///is used to initialize the function to create a paged array. function Initarray () {for ($i =0; $i < $this->sub_pages; $i + +) {$this->page_array[$i]= $i;} return $this->page_array; }/* Construct_num_page The function uses to construct the displayed entry even if: [1][2][3][4][5][6][7][8][9][10] */function construct_num_page () {if ($this-& Gt;pagenums < $this->sub_pages) {$current _array=array (); for ($i =0; $i < $this->pagenums; $i + +) {$current _array[$i]= $i +1; }}else{$current _array= $this->initarray (); if ($this->current_page <= 3) {for ($i =0; $i
Current_page <= $this->pagenums && $this->current_page > $this->pagenums-$this->sub_pages + 1) {for ($i =0; $i
Pagenums)-($this->sub_pages) +1+ $i; }}else{for ($i =0; $i
current_page-2+ $i; }}} return $current _array; }/* Constructs normal Mode page Total 4,523 records, each page shows 10, current 1th/453 page [first] [prev] [next] [last] */function SubPageCss1 () {$subPageCss 1str= ""; $SUBPAGECSS 1str.= "Total". $this->nums. " Record, "; $subPageCss 1str.= "per page". $this->each_disnums. " Article, "; $subPageCss 1str.= "Current section". $this->current_page. " /". $this->pagenums." Page "; if ($this->current_page > 1) {$firstPageUrl = $this->subpage_link. " 1 "; $PREWPAGEURL = $this->subpage_link. ($this->current_page-1); $subPageCss 1str.= "[Home]"; $subPageCss 1str.= "[prev]"; }else {$subPageCss 1str.= "[Home]"; $subPageCss 1str.= "[prev]"; if ($this->current_page < $this->pagenums) {$lastPageUrl = $this->subpage_link. $this->pagenums; $NEXTPAGEURL = $this->subpage_link. ($this->current_page+1); $subPageCss 1str.= "[next page]"; $subPageCss 1str.= "[Last]"; }else {$subPageCss 1str.= "[next page]"; $subPageCss 1str.= "[Last]"; } return $SUBPAGECSS 1Str; Here you can set the displayed CSS style}//To construct the pagination of the Classic mode current 1th/453 page [first] [prev]1 2 3 4 5 6 7 8 9 10 [next] [last] */function SubPageCss2 () {$subPageCss 2str= ""; $subPageCss 2str.= "Current section". $this->current_page. " /". $this->pagenums." Page "; if ($this->current_page > 1) {$firstPageUrl = $this->subpage_link. " 1 "; $PREWPAGEURL = $this->subpage_link. ($this->current_page-1); $subPageCss 2str.= "[Home]"; $subPageCss 2str.= "[prev]"; }else {$subPageCss 2str.= "[Home]"; $subPageCss 2str.= "[prev]"; } $a = $this->construct_num_page (); for ($i =0; $i
Current_page) {$subPageCss 2str.= "[
". $s."]"; }else{$url = $this->subpage_link. $s; $subPageCss 2str.= "[". $s. "]";}} if ($this->current_page < $this->pagenums) {$lastPageUrl = $this->subpage_link. $this->pagenums; $NEXTPAGEURL = $this->subpage_link. ($this->current_page+1); $subPageCss 2str.= "[next page]"; $subPageCss 2str.= "[Last]"; }else {$subPageCss 2str.= "[next page]"; $subPageCss 2str.= "[Last]"; } return $SUBPAGECSS 2Str; }}//Use the following/*include ('.. /mysql.php ')///per page $page _size=3;//Total number of entries $sql=mysql_query ("select * from ' Stu_info '"); $nums =mysql_num_rows ($sql) ;//The number of pages displayed each time $sub _pages=10;//gets the current page if (!isset ($_get["P"])) {$pageCurrent = 1;} else{$pageCurrent =$_get["P"];} $subPages =new Subpages ($page _size, $nums, $pageCurrent, $sub _pages, "page.php?p="); $page = $subPages->subpagecss2 (); echo $page;//Here you can set the CSS style $ss =mysql_query ("select * from ' stu_info ' limit". $page _size* ($pageCurrent-1). ",". $page _size ); while ($row =mysql_fetch_array ($SS)) {echo $row [' Stunum ']. $row [' Stuname ']. $row [' Clanum ']. '
'; }*/?>
I hope this article is helpful to you in PHP programming.
Articles you may be interested in:
- Two All-purpose PHP paging class
- PHP Simple Pagination Class implementation method
- PHP Pagination Class Collection
- An instance of Thinkphp page class modified by Dedecms drop-down page style
- Efficient MongoDB PHP Paging class (Do not use skip)
- thinkphp use of experience sharing-page class page usage
- Thinkphp the use of pagination class
- Beautiful PHP Pagination Class code
- PHP Paging Class code (simple and easy-to-use)
- PHP Ajax Pagination Class code
http://www.bkjia.com/PHPjc/1084534.html www.bkjia.com true http://www.bkjia.com/PHPjc/1084534.html techarticle PHP Custom pagination Class Complete example, this article describes the PHP custom paging class. Share to everyone for your reference, specifically as follows: Phpheader ("content-type:text/html; Charset=utf-8 ") ...