PHP to implement a simple and practical page-type code _php skills

Source: Internet
Author: User
Tags php class prev

The examples in this article describe the simple and practical application of the paging class in PHP. Share to everyone for your reference, specific as follows:

<?php class Page {private $total;  Total record private $pagesize;     How many private $limit to display per page;      Limit private $page;   Current page number private $pagenum;      Total page number private $url;   Address private $bothnum;  The volume//construct method of maintaining digital pagination on both sides initializes the public function __construct ($_total, $_pagesize) {$this->total = $_total? $_total:
     1;
     $this->pagesize = $_pagesize;
     $this->pagenum = ceil ($this->total/$this->pagesize);
     $this->page = $this->setpage (); $this->limit = "Limit".
     ($this->page-1) * $this->pagesize. ", $this->pagesize";
     $this->url = $this->seturl ();
   $this->bothnum = 2;
   }//Interceptor Private Function __get ($_key) {return $this->$_key;
          //Get current page number Private function Setpage () {if (!empty ($_get[' page ')) {if ($_get[' page '] > 0) {
          if ($_get[' page '] > $this->pagenum) {return $this->pagenum; else {REturn $_get[' page '];
        } else {return 1;
     } else {return 1;
     }//Get address Private Function SetUrl () {$_url = $_server["Request_uri"];
     $_par = Parse_url ($_url);
        if (isset ($_par[' query ')) {parse_str ($_par[' query '],$_query);
        unset ($_query[' page ')); $_url = $_par[' path '.
     Http_build_query ($_query);
   return $_url; }//Digital directory Private Function PageList () {for ($i = $this->bothnum; $i >=1; $i-) {$_page = $this->page-
      $i;
        if ($_page < 1) continue; $_pagelist. = ' <a href= '. $this->url. ' &page= '. $_page. ' " > '. $_page. '
     </a> '; $_pagelist. = ' <span class= ' me ' > '. $this->page. '
     </span> ';
        For ($i =1 $i <= $this->bothnum; $i + +) {$_page = $this->page+ $i;
        if ($_page > $this->pagenum) break; $_pagelist. = ' <a href= '. $this->url. ' &page= '. $_page. ' " > '. $_page.'
     </a> ';
   return $_pagelist; //Home Private Function First () {if ($this->page > $this->bothnum+1) {return ' <a href= ' . $this->url. ' "
     >1</a> ... '; }//previous Private Function prev () {if ($this->page = = 1) {return ' <span class= ' disabled ' >
     Previous page </span> '; Return ' <a href= '. $this->url. ' &page= '. ($this->page-1). "
   > Prev </a> '; //Next page Private function next () {if ($this->page = = $this->pagenum) {return ' <span class= ' di
     sabled "> Next page </span>"; Return ' <a href= '. $this->url. ' &page= '. ($this->page+1). "
   > next page </a> '; //End Private Function last () {if ($this->pagenum-$this->page > $this->bothnum) {retur N ' ... <a href= '. $this->url. ' &page= '. $this->pagenum. ' " > '. $this->pagenum. '
     </a> '; //Paging Information public function ShowpagE () {$_page. = $this->first ();
     $_page. = $this->pagelist ();
     $_page. = $this->last ();
     $_page. = $this->prev ();
     $_page. = $this->next ();
   return $_page;

 }}?>

The pagination style is shown in the following illustration:

Instructions for use:

<?php
  $_page = new page ($_total,$_pagesize);
  Where $_total is the total number of bars in the dataset, $_pagesize is the number of display per page.
>

More interested in PHP related content readers can view the site topics: "PHP file Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "Basic PHP Grammar Introduction Tutorial", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"

I hope this article will help you with the PHP program design.

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.