/**
- * * Generic PHP paging class. (Imitation Google style)
- * * Simply provide two parameters for the total number of records and the number of displays per page. (Detailed usage instructions are attached.)
- * * No URL is specified and the link is generated by the program. Facilitates the retrieval of results by paging.
- * * The form is submitted with the Get method, which guarantees that the URL parameters are not lost when operations such as queries, deletions, and so on.
- **/
- Class pager{
- IE Address Bar address
- var $url;
- Record total number of bars
- var $countall;
- Total pages
- var $page;
- Pagination Digital Link
- var $thestr;
- Home page, Previous link
- var $backstr;
- Last page, Next link
- var $nextstr;
- Current page number
- var $pg;
- Show number of records per page
- var $countlist;
- Page Flip Style
- var $style;
- constructor, which executes the function automatically when instantiating the class
- function Pager ($countall, $countlist, $style = "page") {
- Number of records and the number of display per page can not be a whole, the page after the remainder plus 1
- $this->countall = $countall;
- $this->countlist = $countlist;
- $this->style= $style;
- if ($this->countall% $this->countlist!=0) {
- $this->page=sprintf ("%d", $this->countall/$this->countlist) +1;
- }else{
- $this->page= $this->countall/$this->countlist;
- }
$this->pg=$_get["PG"];
- Ensure that the PG starts from page 1th without specifying the case
- if (!ereg ("^[1-9][0-9]*$", $this->pg) | | empty ($this->PG)) {
- $this->pg=1;
- }
- The page number exceeds the maximum range and takes the maximum value
- if ($this->pg> $this->page) {
- $this->pg= $this->page;
- }
- Gets the current URL. See the bottom of the function entity for specific implementations
- $this->url = Pager::geturl ();
- Replace the wrong format with the correct page number
- if (Isset ($_get["PG"]) && $_get["PG"]!= $this->PG) {
- $this->url=str_replace ("? pg=". $_get["PG"], "? pg= $this->pg", $this->url);
- $this->url=str_replace ("&pg=". $_get["PG"], "&pg= $this->pg", $this->url);
- }
- Generates pagination in digital form 12345.
- if ($this->page<=10) {
- for ($i =1; $i < $this->page+1; $i +) {
- $this->thestr= $this->thestr. PAGER::MAKEPG ($i, $this->PG);
- }
- }else{
- if ($this->pg<=5) {
- for ($i =1; $i <10; $i + +) {
- $this->thestr= $this->thestr. PAGER::MAKEPG ($i, $this->PG);
- }
- }else{
- if (6+ $this->pg<= $this->page) {
- for ($i = $this->pg-4; $i < $this->pg+6; $i + +) {
- $this->thestr= $this->thestr. PAGER::MAKEPG ($i, $this->PG);
- }
- }else{
- for ($i = $this->pg-4; $i < $this->page+1; $i + +) {
- $this->thestr= $this->thestr. PAGER::MAKEPG ($i, $this->PG);
- }
}
- }
- }
- Generate text links on the next page of the previous page
- $this->backstr = pager::gotoback ($this->pg);
- $this->nextstr = Pager::gotonext ($this->pg, $this->page);
- Echo ("Total". $this->countall. "Bar, per page". $this->countlist. " Bar, Total ". $this->page." Page ". $this->backstr. $this->thestr. $this->nextstr);
- }
- Auxiliary functions to generate digital paging
- function Makepg ($i, $PG) {
- if ($i = = $PG) {
- return "style." > ". $i.";
- }else{
- Return "url,5, $i)." class= ". $this->style." >". $i.";
- }
- }
- A function that generates information such as the previous page
- function Gotoback ($PG) {
- if ($pg -1>0) {
- return $this->gotoback= "url,3,0". "class=". $this->style. "' > Home url,2,0). "class=". $this->style. "' > Previous page ";
- }else{
- return $this->gotoback= " first prev";
- }
- }
- A function to generate information such as the next page
- function GoToNext ($PG, $page) {
- if ($pg < $page) {
- Return "url,1,0". "class=". $this->style. " > next page url,4,0). "class=". $this->style. "' > Last ";
- }else{
- Return " next page last ";
- }
- } bbs.it-home.org
- Handles $PG methods in URLs for automatic generation of pg=x
- function Replacepg ($url, $flag, $i) {
- if ($flag = = 1) {
- $temp _PG = $this->pg;
- Return Str_replace ("pg=". $temp _pg, "pg=". $this->pg+1), $url);
- }else if ($flag = = 2) {
- $temp _PG = $this->pg;
- Return Str_replace ("pg=". $temp _pg, "pg=". $this->pg-1), $url);
- }else if ($flag = = 3) {
- $temp _PG = $this->pg;
- Return Str_replace ("pg=". $temp _pg, "pg=1", $url);
- }else if ($flag = = 4) {
- $temp _PG = $this->pg;
- Return Str_replace ("pg=". $temp _pg, "pg=". $this->page, $url);
- }else if ($flag = = 5) {
- $temp _PG = $this->pg;
- Return Str_replace ("pg=". $temp _pg, "pg=". $i, $url);
- }else{
- return $url;
- }
- }
- How to get the current URL
- function GetUrl () {
- $url = "http://". $_server["Http_host"];
- if (Isset ($_server["Request_uri")) {
- $url. =$_server["Request_uri"];
- }else{
- $url. =$_server["Php_self"];
- if (!empty ($_server["query_string")) {
- $url. = "?". $_server["Query_string"];
- }
- }
- Add the Pg=x Word to the current URL
- if (!ereg ("(pg=| pg=|pg=| pg=) ", $url)) {
- if (!strpos ($url, "?")) {
- $url = $url. "? Pg=1 ";
- }else{
- $url = $url. " &pg=1 ";
- }
- }
- return $url;
- }
- }
- ?>
Copy Code |