<? Php
Header ("Content-type: text/html; charset = GBK"); // output encoding to avoid Chinese garbled characters
?>
<Html>
<Head>
<Title> ajax paging demonstration </title>
<Script language = "javascript" src = "ajaxpg. js"> </script>
</Head>
<Body>
<Div id = "result">
<? Php
$ Page = isset ($ _ GET ['Page'])? Intval ($ _ GET ['Page']): 1; // obtain the value of the page in page = 18. If there is no page, the page number is 1.
$ Num = 10; // 10 data entries per page
$ Db = mysql_connect ("localhost", "root", "7529639"); // create a database connection
Mysql_select_db ("cr_download"); // select the database to operate
/*
First, we need to obtain the actual amount of data in the database to determine the specific number of pages to be divided. The specific formula is
Total databases divided by the number of entries displayed on each page, more than one.
That is to say, 10/3 = 3.3333 = 4 there is a remainder, and we need to enter.
*/
$ Result = mysql_query ("select * from cr_userinfo ");
$ Total = mysql_num_rows ($ result); // query all data
$ Url = 'Test. Php'; // Obtain the URL of this page
// Page number calculation
$ Pagenum = ceil ($ total/$ num); // obtain the total number of pages, which is also the last page.
$ Page = min ($ pagenum, $ page); // Get the homepage
$ Prepg = $ page-1; // Previous page
$ Nextpg = ($ page = $ pagenum? 0: $ page + 1); // Next page
$ Offset = ($ page-1) * $ num; // obtain the value of the first parameter of limit. If the first page is (1-1) * 10 = 0, the second page is (2-1) * 10 = 10.
// Start the paging navigation bar code:
$ Pagenav = "show the <B>". ($ total? ($ Offset + 1): 0 ). "</B>-<B> ". min ($ offset + 10, $ total ). "</B> records, total $ total records ";
// If there is only one page, the function will jump out:
If ($ pagenum <= 1) return false;
$ Pagenav. = "<a href = javascript: dopage ('result', '$ url? Page = 1');> homepage </a> ";
If ($ prepg) $ pagenav. = "<a href = javascript: dopage ('result', '$ url? Page = $ prepg ');> Previous page </a> "; else $ pagenav. =" previous page ";
If ($ nextpg) $ pagenav. = "<a href = javascript: dopage ('result', '$ url? Page = $ nextpg ');> Next page </a> "; else $ pagenav. =" next page ";
$ Pagenav. = "<a href = javascript: dopage ('result', '$ url? Page = $ pagenum ');> last page </a> ";
$ Pagenav. = "</select> Page, total $ pagenum page ";
// If the input page number parameter is greater than the total page number, the error message is displayed.
If ($ page> $ pagenum ){
Echo "Error: Can Not Found The page". $ page;
Exit;
}
$ Info = mysql_query ("select * from cr_userinfo limit $ offset, $ num"); // obtain the data to be displayed on the corresponding page
While ($ it = mysql_fetch_array ($ info )){
Echo $ it ['username'];
Echo "<br> ";
} // Display Data
Echo "<br> ";
Echo $ pagenav; // output paging navigation
?>
</Div>
</Body>
</Html>