Php + ajax implement refreshing pagination

Source: Internet
Author: User
This article mainly introduces php + ajax implementation of the method of refreshing new pages, details the implementation of Ajax files and PHP call methods, for more information about php + ajax implementation, see the following example. Share it with you for your reference. The details are as follows:

Limit offset, length;
Page 1
Page 2
Page 3
Number of entries per page: 7
Total number of items: select count (*) from table
Total number of pages: ceil rounded up (total number of lines/number of lines per page)
1. use paging

<? Phpclass Pagination {private $ total; // total number of records in the data table private $ listRows; // The number of rows displayed on each page is private $ limit; // mysql database limit private $ uri; // The uri address before the page information is private $ pageNum; // The number of pages is private $ config = array ('header' => "records ", "prev" => "[previous page]", "next" => "[next Page]", "first" => "[first Page ]", "last" => "[last page]"); private $ listNum = 8; /** $ total number of current information items * $ number of items displayed on each page of listRows * $ page http under pa: // URL/index. php? Page = 5 */public function _ construct ($ total, $ listRows = 10, $ pa = "") {$ this-> total = $ total; $ this-> listRows = $ listRows; $ this-> uri = $ this-> getUri ($ pa); $ this-> page =! Empty ($ _ GET ["page"])? $ _ GET ["page"]: 1; // do not input page, the homepage $ this-> pageNum = ceil ($ this-> total/$ this-> listRows) is displayed by default; $ this-> limit = $ this-> setLimit ();} // set the number of entries displayed per page. private function setLimit () {return "Limit ". ($ this-> page-1) * $ this-> listRows. ", {$ this-> listRows}";} // Obtain the URL address private function getUri ($ pa) {$ url = $ _ SERVER ["REQUEST_URI"]. (strpos ($ _ SERVER ["REQUEST_URI"], '? ')? '':"? "). $ Pa; $ parse = parse_url ($ url); if (isset ($ parse ["query"]) {parse_str ($ parse ['query'], $ params ); unset ($ params ["page"]); $ url = $ parse ['path']. '? '. Http_build_query ($ params);} return $ url;} // magic method, public function _ get ($ args) {if ($ args = "limit ") return $ this-> limit; else return null;} // Number of Entries starting from the page private function start () {if ($ this-> total = 0) return 0; else return ($ this-> page-1) * $ this-> listRows + 1;} // number of end pages private function end () {return min ($ this-> page * $ this-> listRows, $ this-> total);}/* set homepage */private function first () {$ Html = ""; if ($ this-> page = 1) $ html. = ''. $ this-> config ["first"]. ''; else $ html. = "uri} & page = 1 \") '>{$ this-> config ["first"]} "; // $ html. = "uri} & page = 1' >{$ this-> config [" first "]}"; return $ html;}/* set the previous page */private function prev () {$ html = ""; if ($ this-> page = 1) $ html. = ''. $ this-> config ["prev"]. ''; else $ html. = "uri} & page = ". ($ this-> page-1 ). "\") '>{$ this-> config ["prev"]} "; // $ html. = "Uri} & page = ". ($ this-> page-1 ). "'>{$ this-> config [" prev "]}"; return $ html;} // page number list [Homepage] [2] [3 ]............ [Last Page] private function pageList () {$ linkPage = ""; $ inum = floor ($ this-> listNum/2); for ($ I = $ inum; $ I >=1; $ I --) {$ page = $ this-> page-$ I; if ($ page <1) continue; $ linkPage. = "uri} & page = {$ page} \") '> {$ page} ";}$ linkPage. = "{$ this-> page}"; for ($ I = 1; $ I <= $ inum; $ I ++) {$ page = $ this-> page + $ I; if ($ page <= $ this-> pageNum) $ linkPage. = "uri} & page = {$ page} \") '> {$ page} "; else break;} return $ linkPage ;} /* set the next page */private function next () {$ html = ""; if ($ this-> page = $ this-> pageNum) $ html. = ''. $ this-> config ["next"]. ''; else $ html. = "uri} & page = ". ($ this-> page + 1 ). "\") '>{$ this-> config ["next"]} "; // $ html. = "uri} & page = ". ($ this-> page + 1 ). "'>{$ this-> config [" next "]}"; return $ html;}/* Set the last page */private function last () {$ html = ""; if ($ this-> page = $ this-> pageNum) $ html. = ''. $ this-> config ["last"]. ''; else $ html. = "uri} & page = ". ($ this-> pageNum ). "\") '>{$ this-> config ["last"]} "; // $ html. = "uri} & page =. (this-> pageNum ). '>{$ this-> config ["last"]} "; return $ html;}/* set page jump */private function goPage () {return'    ';} // Page list configuration option function fpage ($ display = array (0, 1, 2, 3, 4, 5, 6, 7, 8 )) {$ html [0] = "total{$ This-> total}{$ This-> config ["header"]} "; $ html [1] =" displayed on each page". ($ This-> end ()-$ this-> start () + 1 ).", This page{$ This-> start ()}-{$ this-> end ()}"; $ Html [2] ="{$ This-> page}/{$ this-> pageNum}Page "; $ html [3] = $ this-> first (); $ html [4] = $ this-> prev (); $ html [5] = $ this-> pageList (); $ html [6] = $ this-> next (); $ html [7] = $ this-> last (); $ html [8] = $ this-> goPage (); $ fpage = ''; foreach ($ display as $ index) {$ fpage. = $ html [$ index] ;}return $ fpage ;}}

2. Data Display

<? Php // link to the database // Obtain the specific information // display the header by page ("content-type: text/html; charset = utf-8"); $ link = mysql_connect ('localhost ', 'root', '000000'); mysql_select_db ('shop ', $ link); mysql_query ("set names utf8"); $ css = <
         ajax无刷新分页效果    

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.