The content is dedicated to paging classes as well as specific methods and parsing.
<?php class Page {private $total; Total number of records in the data table private $listRows; Each page shows the number of rows private $limit; The SQL statement uses the LIMIT clause to restrict the number of records to M.N private $uri; Automatically get URL request address private $pageNum; Total pages Private $page; Current page Private $config = array (//config config ' head ' = "record", ' PR EV ' + ' prev ', ' next ' = ' next ', ' first ' = ' home ', ' last ' and ' End ' ); Display content in the paging information, you can set the private $listNum = 10 by the set () method; Default Page list display number//Total 10 page 1/10 previous 1 2 3 4 5 Next/** construction method, you can set the properties of the paging class @param int $tota L Calculate the total number of records for paging @param int $listRows Optional, set the number of records to display per page, default to 25 @param mixed $query optional, to pass parameters to the target page, either an array or a query string format @param bool $ord Optional, the default value is true, the page is displayed from the first page, and false is the last page */Public function __construct ($total, $listRows =25, $query = "", $ord =true) {$this->total = $t Otal; $this->listrows = $listRows; $this->uri = $this->geturi ($query); Gets the address in the browser address bar $this->pagenum = ceil ($this->total/$this->listrows); Total number of pages/* The following judgment is used to set the current face */if (!empty ($_get["page")) {$page = $_get["page"]; }else{if ($ord) $page = 1; else $page = $this->pagenum; if ($total > 0) {if (Preg_match ('/\d/', $page)) {$this->page = 1; }else{$this->page = $page; }}else{$this->page = 0; } $this->limit = "Limit". $this->setlimit (); The information used to set the display paging can be manipulated @param string $param is the subscript of the member Property array config @param s The Tring $value is used to set the element value corresponding to the config subscript @return object returns to the object itself $this, for use in a habitual operation */funct Ion Set ($param, $value) {if (Array_key_exists ($param, $this->config)) {$this->config[$param ] = $value; } return $this; }/* is not a direct call, this method allows you to get the value of the private member property, limit and page directly outside the object */function __get ($args) {if ($args = = "Limit" | | $args = = "page") return $this-$args; else return null; /** output pagination @param the number of int 0-7 as a parameter for customizing the output paging structure and the order of the structure in the specified format, with the default output of all structures @return String Paging information content */
Total 10 page 1/10 previous 1 2 3 4 5 Next function fpage () {$arr = Func_get_args (); $html [0] = "<span class= ' p1 ' > total <b> {$this->total} </b>{$this->config[" Head "]}& Nbsp;</span> "; Total 100 records $html [1] = " page <b>". $this->disnum (). " </b> Bar "; Page 10 (because the last page is not sure) $html [2] = " this page from <b>{$this->start ()}-{$this->end ()}</b> strip ;"; This page from 11-20 $html [3] = " <b>{$this->page}/{$this->pagenum}</b> page "; 2/10 page $html [4] = $this->firstprev (); First Prev $html [5] = $this->pagelist (); 1 2 3 4 5 $html [6] = $this->nextlast (); Next last $html [7] = $this->gopage (); [] Go (jump) $fpage = ' <div style= ' font:12px \ ' \5b8b\4f53\ ', San-serif; " > '; if (cOunt ($arr) < 1) $arr = Array (0, 1,2,3,4,5,6,7); for ($i = 0; $i < count ($arr); $i + +) $fpage. = $html [$arr [$i]]; $fpage. = ' </div> '; return $fpage; }/* Private method used inside the object, */Private Function Setlimit () {if ($this->page > 0) Return ($this->page-1) * $this->listrows. ", {$this->listrows}"; else return 0; }/* Private method used inside the object to automatically get access to the current URL */Private function GetURI ($query) {$request _uri = $_server[ "Request_uri"]; $url = Strstr ($request _uri, '? ')? $request _uri: $request _uri. '? '; if (Is_array ($query)) $url. = Http_build_query ($query); else if ($query! = "") $url. = "&". Trim ($query, "?&"); $arr = Parse_url ($url); if (Isset ($arr ["Query"])) {PARSE_STR ($arr["Query"], $arrs); unset ($arrs ["page"]); $url = $arr ["path"]. '? '. Http_build_query ($ARRS); } if (Strstr ($url, '? ')) {if (substr ($url,-1)! = '? ') $url = $url. ' & '; }else{$url = $url. '? '; } return $url; }/* Private method used inside the object to get the number of records starting at the current page */Private Function Start () {if ($this->total = = 0) return 0; else return ($this->page-1) * $this->listrows+1; }/* Private method used inside the object to get the number of records at the end of the current page */Private Function End () {return min ($this->page * $this ListRows, $this->total); //min takes two small, private methods used inside the object to get information about the previous and first page operations private function Firstprev () {if ($this->p Age > 1) {$str = " <a href= ' {$this->uri}page=1 ' >{$this->config[" First "]}</a> &nBSP; "; $str. = "<a href= ' {$this->uri},page=". ($this->page-1). "' >{$this->config["prev"]}</a> "; return $str; The private method used inside the object to get the page number table information private Function pagelist () {$linkPage = " < B> "; $inum = Floor ($this->listnum/2);//floor Down/* The list before the current page */for ($i = $inum; $i >= 1; $i-) { $page = $this->page-$i; if ($page >= 1) $linkPage. = "<a href= ' {$this->uri}page={$page} ' >{$page}</a> "; }/* Information for the current page */if ($this->pagenum > 1) $linkPage. = "<span style= ' padding:1px 2px;background: #BBB; Color:white ' >{$this->page}</span> "; /* The list after the current page */for ($i =1; $i <= $inum; $i + +) {$page = $this->page+ $i; if ($page <= $thiS->pagenum) $linkPage. = "<a href= ' {$this->uri}page={$page} ' >{$page}</a> "; else break; } $linkPage. = ' </b> '; return $linkPage; The private method used inside the object to get the operation information for the next and last page Private function nextlast () {if ($this->page! = $this->pagenu m) {$str = " <a href= ' {$this->uri}page=". $this->page+1). "' >{$this->config["Next"]}</a> "; $str. = " <a href= ' {$this->uri}page=". ($this->pagenum). "' >{$this->config["last"]}</a> "; return $str; The private method used inside the object to display and process the form jump page Private Function gopage () {if ($this->pagenum > 1 {return ' <input style= ' width:20px;height:17px!important;height:18px;border:1px solid #CCCC CC; "type=" text "onkeydown=" Javascript:if (Event.keycode==13) {var page= (this.value> '. $this->pagenum. ')? '. $this->pagenum ': this.value;location=\ '. $this->uri. ' Page=\ ' +page+\ '} "value=" '. $this->page. ' " ><input style= "cursor:pointer;width:25px;height:18px;border:1px solid #CCCCCC;" type= "button" value= "GO" onclick= "Javascript:var page= (this.previoussibling.value> '. $this->pagenum. ')? '. $this->pagenum ': this.previoussibling.value;location=\ '. $this->uri. ' Page=\ ' +page+\ ' > '; The private method used inside the object to get the number of record bars displayed on this page private function Disnum () {if ($this->total > 0) { return $this->end ()-$this->start () +1; }else{return 0; } } }
The reference operation is as follows:
<! DOCTYPE html>
"--end--"
Peacock fly Southeast, five miles a wandering. 13 can weave the vegetarian, 14 learn to cut clothes. Konghou, 16 chanting poetry. 17 for the June woman, the heart often bitter sorrow. June is not only for the government officials, the love of the feast. The humble concubine empty room, meet often day thin.
The chickens are woven into the machine and are not allowed to rest. 3rd Broken five pi, adults so too late. Not for weaving late, June family woman difficult. The concubine was so driven that the apostles left nothing to do. Can be Bai Pang, timely and return. Government officials have to smell, classroom kai-ah mother.
The son has been thin LU phase, fortunately the woman. Hair knot with gossiped, the death of a total of friends. Working for two or three years, beginning is not long. The female does not have the deviation, the absent causes is not thick. Elmo called the government officials, Henetia district. This woman does not have the courtesy, moves from the specialized.
Guoi Jiu Hui indignation, thou shalt be free. The club has a virtuous woman, since the name Chinlo apply. The poor are matchless, and the mother asks for thee. Can be dispatched quickly, sent to caution Mo stay. The government officials knelt, but the start of the mother of the Lord. If this woman were to be dispatched, she would not marry.
A mother had to smell it, and the hammer-bed was furious. He has no fear, and he dares to help the woman. I have lost Grace, will not from the Xu. The government is silent, and then worship the household. Say the bride, choked speechless. I do not drive the Qing, forcing the mother.
Qing but temporarily haigu, I now and the house. Soon when it is returned, it will be welcomed. With this in mind, be careful not to violate my language. The bride called the government officials, do not re-weigh. At the beginning of the past, Shei Jialai your door. He who is in the public, dares to be self-devoted.
Day and night routine, lingping and bitter. It is said that there is no sin and support for Groß. Still more to be expelling, say again. Concubine has embroidered waist undergarment, luxuriantly self-born light. The Red Nile Tent, Four corners of sachet. Box Curtain Sixty or seventy, green blue hair rope.
Things are different, all kinds of them. People are cheap, not enough to welcome posterity. Left to be dispatched, there is no reason for this. Always for comfort, long mo forget. The chicken is out to Shu, the bride from the strict makeup. I embroidered the skirt, everything four or five pass.
Tread nie silk, with tortoise-light on the head. If the waist is ceruse, the moon when the ear. Refers to the onion root, such as the mouth containing beads dan. Delicate step, exquisite world incomparable. In the Shaia, the mother listened to anger. When I was a daughter, I was born small.
This is no lesson, and unworthy of your own. The mother coin is too much to be driven by mother. Today Haigu go, read Mother Lao's home. But with her sister-in-the-Eyes, tears fall. When the bride first came, her sister began to bed. Today was expelling, sister-in-chief like me.
The diligent heart raises the public basking, is good to own to support will. When初七because and the next nine, play Mo-phase forget. Go out to the board, tears fall hundreds of rows. Government officials horse in front, bride car in the rear. The faint of the meadow, will be the mouth of the chase. Dismounted into the car, bowed his head and whispered.
The oath is not separated from Qing, and temporarily haigu to go. I now and go to the house, soon when return. The oath of the day is not negative, the bride called the government officials. Feeling June only bosom, June if see record. Soon the king came, and June as a rock.
Php+mysql pagination Classes and references