Another php paging class implementation code. Copy the code as follows :? Phpfunctiongenpage (total number of pages, total records, per page, current page $ _ GET [page]; if ($ page0) $ page1; $ eachpage $ page_size; $ pagesqls
The code is as follows:
Function genpage (& $ SQL, $ page_size = 10)
{
Global $ pages, $ sums, $ eachpage, $ page; // total number of pages, total records, per page, current page
$ Page = $ _ GET ["page"];
If ($ page = 0) $ page = 1;
$ Eachpage = $ page_size;
$ Pagesql = strstr ($ SQL, "from ");
$ Pagesql = "select count (*) as ids". $ pagesql;
$ Conn = mysql_query ($ pagesql) or die (mysql_error ());
If ($ rs = mysql_fetch_array ($ conn) $ sums = $ rs [0];
$ Pages = ceil ($ sums/$ eachpage );
If ($ pages = 0) $ pages = 1;
$ Startpos = ($ page-1) * $ eachpage;
$ SQL. = "limit $ startpos, $ eachpage ";
}
// Display the page
Function showpage ()
{
Global $ pages, $ sums, $ eachpage, $ page; // total number of pages, total records, number of pages, current page, and other parameters
$ Link = $ _ SERVER ['php _ SELF '];
Echo "record". $ sums. ":". $ eachpage ."";
Echo "page". $ page. "/". $ pages ."";
$ P_head = $ page-5;
If ($ p_head <= 0) $ p_head = 1; // The first five page number cycles start
$ P_end = $ page + 5;
If ($ p_end> $ pages) $ p_end = $ pages; // The last five page number cycles.
Echo "[Homepage]";
For ($ I = $ p_head; $ I <= $ p_end; $ I ++)
{
If ($ I! = $ Page)
Echo "[$ I]";
Else
Echo"
[$ I]
";
}
Echo "[last page]";
}
?>
The http://www.bkjia.com/PHPjc/320975.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/320975.htmlTechArticle code is as follows :? Php function genpage (// total number of pages, total records, per page, current page $ page = $ _ GET ["page"]; if ($ page = 0) $ page = 1; $ eachpage = $ page_size; $ pagesql = s...