Implementation of the PHP paging class

Source: Internet
Author: User
In our previous two articles, we show you the principle of PHP paging and the implementation of the page, the two articles are implemented in the development of paging, each time to write a large number of PHP code, then we can put the page into a package, write a class, and then directly call it? Today to share with you a good-looking PHP page Class!

This article introduces a native PHP paging class, which has a somewhat similar bootstrap style to the page.

<?php/* * ********************************************* * @ class Name: Page * @ parameter: $myde _total-Total records * $myde _size -Number of records displayed on a page * $myde _page-Current page * $myde _url-Get current URL * @ Feature: Paging implementation * @ Author: Song Hai */class page {Priva          Te $myde _total;           Total record number private $myde _size;           Number of records displayed on one page private $myde _page;     Current page private $myde _page_count;              Total pages Private $myde _i;             Beginning pages private $myde _en;            End pages Private $myde _url;     Gets the current URL */* * $show _pages * page display format, showing the number of pages linked to $show _pages+1.    * such as $show_pages=2 so the page is displayed is [home] [prev] 1 2 3 4 5 [next] [last] * * Private $show _pages; Public function construct ($myde _total = 1, $myde _size = 1, $myde _page = 1, $myde _url, $show _pages = 2) {$this        Myde_total = $this->numeric ($myde _total);        $this->myde_size = $this->numeric ($myde _size);        $this->myde_page = $this->numeric ($myde _page); $this->myde_page_count = Ceil ($this->myde_total/$this->myde_size);        $this->myde_url = $myde _url;        if ($this->myde_total < 0) $this->myde_total = 0;        if ($this->myde_page < 1) $this->myde_page = 1;        if ($this->myde_page_count < 1) $this->myde_page_count = 1;        if ($this->myde_page > $this->myde_page_count) $this->myde_page = $this->myde_page_count;        $this->limit = ($this->myde_page-1) * $this->myde_size;        $this->myde_i = $this->myde_page-$show _pages;        $this->myde_en = $this->myde_page + $show _pages;            if ($this->myde_i < 1) {$this->myde_en = $this->myde_en + (1-$this->myde_i);        $this->myde_i = 1; if ($this->myde_en > $this->myde_page_count) {$this->myde_i = $this->myde_i-($this-&            gt;myde_en-$this->myde_page_count); $this->myde_en = $this->myde_page_count;    } if ($this->myde_i < 1) $this->myde_i = 1; }//detects whether the digital private function numeric ($num) {if (strlen ($num)) {if (!preg_match ("/^[0-9]+$/", $nu            m)) {$num = 1;            } else {$num = substr ($num, 0, 11);        }} else {$num = 1;    } return $num;    }//Address replaces private function Page_replace ($page) {return str_replace ("{page}", $page, $this->myde_url); }//Home Private Function Myde_home () {if ($this->myde_page! = 1) {return "<a href= '". $thi S->page_replace (1).        "' title= ' Home > Home </a>";        } else {return "<p> home </p>"; }}//previous Private Function Myde_prev () {if ($this->myde_page! = 1) {return "<a href= '" . $this->page_replace ($this->myde_page-1).        "' title= ' prev > prev </a>";          } else {  Return "<p> prev </p>";            }}//Next Private Function Myde_next () {if ($this->myde_page! = $this->myde_page_count) { Return "<a href= '". $this->page_replace ($this->myde_page + 1).        "' title= ' next page ' > Next </a>";        } else {return ' <p> next </p> ';            }}//Last Private Function Myde_last () {if ($this->myde_page! = $this->myde_page_count) { Return "<a href= '". $this->page_replace ($this->myde_page_count).        "' title= ' last ' > Last </a>";        } else {return ' <p> last </p> '; }}//Output public function myde_write ($id = ' page ') {$str = "<div id=". $id.        ">";        $str. = $this->myde_home ();        $str. = $this->myde_prev ();        if ($this->myde_i > 1) {$str. = "<p class= ' pageellipsis ' >...</p>";     } for ($i = $this->myde_i; $i <= $this->myde_en; $i + +) {       if ($i = = $this->myde_page) {$str. = "<a href= '". $this->page_replace ($i). "' title= '." $i.            "Page ' class= ' cur ' > $i </a>"; } else {$str. = "<a href= '". $this->page_replace ($i). "' title= '." $i.            "Page > $i </a>"; }} if ($this->myde_en < $this->myde_page_count) {$str. = "<p class= ' pageellipsis ' >        ...</p> ";        } $str. = $this->myde_next ();        $str. = $this->myde_last (); $str. = "<p class= ' Pageremark > Total <b>".                $this->myde_page_count. "</b> page <b>". $this->myde_total.        "</b> data </p>";        $str. = "</div>";    return $str; }}?>

:

Summarize:

PHP paging in the actual development can not write so much code, we can write a PHP paging class, can be common, in the development of the later can be brought directly to call, do not need to write it again!

Related recommendations:

The implementation principle of PHP paging


Example of PHP for paging effect


How to write PHP paging code


How to use PHP to make paged queries

Related Article

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.