Copy codeThe Code is as follows:
<? Php
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 "[<a href = $ link? Page = 1> homepage </a>] ";
For ($ I = $ p_head; $ I <= $ p_end; $ I ++)
{
If ($ I! = $ Page)
Echo "<a href = $ link? Page = $ I> [$ I] </a> ";
Else
Echo "<B> <strike> [$ I] </strike> </B> ";
}
Echo "[<a href = $ link? Page = $ pages> last page </a>] ";
}
?>