PHP custom pagination class complete instance _php tips

Source: Internet
Author: User

This example describes the PHP custom paging class. Share to everyone for your reference, specific as follows:

<?php header ("content-type:text/html;
Charset=utf-8 "); Class subpages{Private $each _disnums;//The number of entries displayed per page private $nums;//Total number of entries private $current _page;//the currently selected page private $sub _pag es;//the number of pages per display private $pageNums//Total number of pages private $page _array = Array ();//the array used to construct the pagination private $subPage _link;//the links for each page//priva
     Te $subPage _type;//Display the type of paging/* when @subpage_type=1 for normal paging mode example: Total 4,523 records, each page shows 10, the current 1th 453 page [first] [prev] [Next page] [last page] When @subpage_type=2 the classic pagination style example: The current 1th 453 page [first] [prev] 1 2 3 4 5 6 7 8 9 10 [next page] [last] * function __construct ($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); }//Show_subpages functions in constructorsSurface.
   The paging/function show_subpages ($subPage _type) {if ($subPage _type = 1) {$this->subpagecss1 () is used to determine what is displayed.
   }else if ($subPage _type = = 2) {$this->subpagecss2 ();
 }////used to initialize the array of pagination.
 function Initarray () {for ($i =0; $i < $this->sub_pages; $i + +) {$this]= $i->page_array[$i;
  return $this->page_array; }/* Construct_num_page The function is used to construct the displayed entry even if: [1][2][3][4][5][6][7][8][9][10]/function Construct_num_page () {if ($this-
   >pagenums < $this->sub_pages) {$current _array=array ();
   For ($i =0 $i < $this->pagenums; $i + +) {$current _array[$i]= +1;
   }else{$current _array= $this->initarray ();
    if ($this->current_page <= 3) {for ($i =0; $i <count ($current _array); $i + +) {$current _array[$i]= $i +1;  }else if ($this->current_page <= $this->pagenums && $this->current_page > $this->pagenums- $this->sub_pages + 1) {for ($i =0; $i <count ($current _array); $i + +) {$current _array[$i]= ($this->pagenums)-($this->sub_pages) +1+ $i;
    }else{for ($i =0; $i <count ($current _array) $i + +) {$current _array[$i]= $this->current_page-2+ $i;
  }} return $current _array;
  }/* Constructs common Mode page Total 4,523 records, each page shows 10, the current 1th 453 page [first] [prev] [Next page] [last]/function SubPageCss1 () {$subPageCss 1str= ""; $subPageCss 1str.= "altogether". $this->nums. "
  Record, "; $SUBPAGECSS 1str.= "Display 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.= "[<a href= ' $firstPageUrl ' > Home </a>]";
  $subPageCss 1str.= "[<a href= ' $prewPageUrl ' > previous page </a>]";
   }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.= "[<a href= ' $nextPageUrl ' > Next page </a>]";
  $subPageCss 1str.= "[<a href= ' $lastPageUrl ' > Last </a>]";
   }else {$subPageCss 1str.= "[next page]";
  $subPageCss 1str.= "[Last]"; return $SUBPAGECSS 1Str;
  Here you can set the CSS styles that are displayed}/* Construction Classic mode pagination current 1th/453 page [first] [prev] 1 2 3 4 5 6 7 8 9 10 [next page] [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.= "[<a href= ' $firstPageUrl ' > Home </a>]";
  $subPageCss 2str.= "[<a href= ' $prewPageUrl ' > previous page </a>]";
   }else {$subPageCss 2str.= "[Home]";
  $subPageCss 2str.= "[prev]";
  $a = $this->construct_num_page ();
   For ($i =0 $i <count ($a); $i + +) {$s = $a [$i]; if ($s = = $this->current_page) {$subPAgecss2str.= "[<span style= ' color:red;font-weight:bold; > ". $s."
   </span>] ";
    }else{$url = $this->subpage_link. $s; $subPageCss 2str.= "[<a href= ' $url ' >". $s. "
   </a>] ";
   } if ($this->current_page < $this->pagenums) {$lastPageUrl = $this->subpage_link. $this->pagenums; $NEXTPAGEURL = $this->subpage_link.
   ($this->current_page+1);
   $subPageCss 2str.= "[<a href= ' $nextPageUrl ' > Next page </a>]";
  $subPageCss 2str.= "[<a href= ' $lastPageUrl ' > Last </a>]";
   }else {$subPageCss 2str.= "[next page]";
  $subPageCss 2str.= "[Last]";
  return $SUBPAGECSS 2Str; }//Use the following/*include (' ...
/mysql.php ');
The number of bars displayed 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 per display $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 CSS styles $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 ']. '
 <br> '; }*/?>

I hope this article will help you with your PHP programming.

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.