PHP Generic paging class page. php [Imitation google paging] & lt ;? Php/*** common php paging class. (Similar to Google style) ** you only need to provide two parameters: the total number of records and the number of entries displayed on each page. (Detailed instructions...) ** you do not need to specify a URL. the link is generated by the program. It is convenient for querying results by page. ** The form uses the GET method to improve the PHP Generic paging class page. php [like google paging]
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"]; // make sure that pg starts from page 1st if (! Ereg ("^ [1-9] [0-9] * $", $ this-> pg) | empty ($ this-> pg )) {$ this-> pg = 1;} // The page number exceeds the maximum value. if ($ this-> pg> $ this-> page) {$ this-> pg = $ this-> page;} // Obtain the current URL. For specific implementation, see the function entity at the bottom $ this-> url = Pager: getUrl (); // replace the incorrect 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 the form of numbers such as 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 such as the previous page and Next Page $ this-> backstr = Pager :: gotoback ($ this-> pg); $ this-> nextstr = Pager: gotonext ($ this-> pg, $ this-> page ); // echo ("total ". $ this-> countall. "entries, per page ". $ this-> countlist. "entries, total ". $ this-> page. "page ". $ this-> backstr. $ this-> thestr. $ this-> nextstr);} // the auxiliary function for generating digital paging: makepg ($ I, $ pg) {if ($ I = $ pg) {return "style. "'> ". $ I. "";} else {return "url, 5, $ I ). "class = '". $ this-> style. "'>". $ I ."";}}// Function for generating information such as previous pages gotoback ($ pg) {if ($ PG-1> 0) {return $ this-> gotoback =" url, 3, 0 ). "class = '". $ this-> style. "'> homepage url, 2, 0 ). "class = '". $ this-> style. "'> Previous Page";} else {return $ this-> gotoback = "style. "'> homepage previous page" ;}}// function for generating information such as the next page: gotonext ($ pg, $ page) {if ($ pg <$ page) {return "url, 1, 0 ). "class = '". $ this-> style. "'> Next Page url, 4, 0 ). "class = '". $ this-> style. "'> last page";} else {return "style. "'> End of Next page Page ";}} // process the $ pg method in the url, used to automatically generate 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 ;}// method for obtaining 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 pg = x 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 ;}}?>
?