The function source code is displayed on pages in php. Php pagination function Source code! DOCTYPEhtmlPUBLIC-W3CDTDXHTML1.0TransitionalENwww.w3.orgTRxhtml1DTDxhtml1-transitional.dtdhtmlxmlnswww.w3.org1999 php pagination function Source code
Google paging
Require ('web _ page. php'); // contains paging programs
// Database configuration
$ Mysql_host = 'localhost'; // database server
$ Mysql_user = 'root'; // database username
$ Mysql_pass = '000000'; // database password
$ Mysql_db = 'test'; // database name
// Connect to the mysql database
$ Link = mysql_connect ($ mysql_host, $ mysql_user, $ mysql_pass) or die ('connection to MYSQL Server Error ');
Mysql_select_db ($ mysql_db, $ link) or die ('connection to MYSQL database error ');
// Start by page
$ SQL _page = "select news_id, news_title from cms_news order by news_id desc ";
$ SQL = mysql_query ($ SQL _page );
$ Num = mysql_num_rows ($ SQL); // The total number of rows.
$ Max = 1; // number of entries per page
$ Pagenum = ceil ($ num/$ max); // number of split pages
If (! Isset ($ _ GET ['Page']) or! Intval ($ _ GET ['Page']) or! Is_numeric ($ _ GET ['Page']) or $ _ GET ['Page']> $ pagenum ){
$ Page = 1; // when the page number does not exist, it is not in decimal format. The number is greater than or equal to 1.
} Else {
$ Page = $ _ GET ['Page']; // The current page number.
}
$ Min = ($ page-1) * $ max; // The current page starts with $ min
$ SQL = "{$ SQL _page} limit $ min, $ max ";
Echo'
';
If ($ num ){
$ SQL = mysql_query ($ SQL );
For (; $ row = mysql_fetch_array ($ SQL );){
Echo'
'. $ Row ['news _ title'].'';
}
} Else {
Echo'
None';
}
Echo'
';
// Mysql_free_result ($ SQL); // release resources
?>
// End by page
Mysql_close ();
?>
The above is the calling method. The following is the paging program.
Function web_page ($ pageurl = "", $ pageselect = true ){
Global $ page, $ num, $ pagenum; // The total number of pages of the current page.
Echo "$ num records in total ,";
$ Uppage = $ page-1; // Previous page
$ Downpage = $ page + 1; // Next page
$ Lr = 5; // display the number of page connections
$ Left = floor ($ lr-1)/2); // The number of page connections displayed on the left
$ Right = floor ($ lr/2); // Number of page connections displayed on the right
// Find the start page and end page below
If ($ page <= $ left) {// if the current page is left insufficient, the page number is displayed.
$ Leftpage = 1;
$ Rightpage = ($ lr <$ pagenum )? $ Lr: $ pagenum );
} Elseif ($ pagenum-$ page) <$ right) {// if the right of the current page is insufficient
$ Leftpage = ($ pagenum <$ lr )? 1 :( $ pagenum-$ lr + 1 ));
$ Rightpage = $ pagenum;
} Else {// displays the number of pages left and right
$ Leftpage = $ page-$ left;
$ Rightpage = $ page + $ right;
}
// Front $ lr page and back $ lr page
$ Qianpage = ($ page-$ lr) <1? 1 :( $ page-$ lr ));
$ Houpage = ($ page + $ lr)> $ pagenum? $ Pagenum :( $ page + $ lr ));
// Output page
If ($ page! = 1 ){
Echo "<";
} Else {
Echo "<";
}
For ($ pages = $ leftpage; $ pages <= $ rightpage; $ pages ++ ){
If ($ pages = $ page ){
Echo "$ pages ";
} Else {
Echo "$ pages ";
}
}
If ($ page! = $ Pagenum ){
Echo ">>> ";
} Else {
Echo ">>> ";
}
// Jump
$ Javapage = <