<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> google paging </title>
<Meta name = "keywords" content = "google php pagination program"/>
<Meta name = "description" content = "google php pagination program"/>
<Style type = "text/css">
<! --
Body {font-family: Arial, Helvetica, sans-serif; font-size: 12px; margin: 0px; padding: 0px ;}
Div {height: auto; width: 800px; margin: 10px auto; line-height: 20px ;}
/* CSS manu style pagination */
. Manu {
PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center
}
. Manu {
BORDER-RIGHT: # eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: # eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: # eee 1px solid; COLOR: #036cb4; PADDING-TOP: 2px; BORDER-BOTTOM: # eee 1px solid; TEXT-DECORATION: none
}
. Manu A: hover {
BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; COLOR: #666; BORDER-BOTTOM: #999 1px solid
}
. Manu A: active {
BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; COLOR: #666; BORDER-BOTTOM: #999 1px solid
}
. Manu. current {
BORDER-RIGHT: #036cb4 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #036cb4 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #036cb4 1px solid; COLOR: # fff; PADDING-TOP: 2px; BORDER-BOTTOM: #036cb4 1px solid; BACKGROUND-COLOR: #036cb4
}
. Manu. disabled {
BORDER-RIGHT: # eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: # eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: # eee 1px solid; COLOR: # ddd; PADDING-TOP: 2px; BORDER-BOTTOM: # eee 1px solid
}
-->
</Style>
</Head>
<Body>
<? Php
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 '<div> ';
If ($ num ){
$ SQL = mysql_query ($ SQL );
For (; $ row = mysql_fetch_array ($ SQL );){
Echo '<li> <a href = "show. php? Id = '. $ row ['news _ id'].' "> '. $ row ['news _ title'].' </a> </li> ';
}
} Else {
Echo '<li> none </li> ';
}
Echo '</div> ';
// Mysql_free_result ($ SQL); // release resources
?>
<Div class = "manu"> <? Php web_page (""); // call the output page to reference other parameters of your page, such as web_page ("& class = 2 & news = 6")?> </Div>
<? Php
// End by page
Mysql_close ();
?>
</Body>
</Html>
The above is the calling method. The following is the paging program.
<? Php
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 "<a title =" homepage "href =" ". $ _ SERVER ['php _ SELF ']."? $ Pageurl "> </a> <a title =" previous page "href =" ". $ _ SERVER ['php _ SELF ']."? Page = $ uppage $ pageurl "> </a> ";
} Else {
Echo "<span class = 'disabled '> </span> ";
}
For ($ pages = $ leftpage; $ pages <= $ rightpage; $ pages ++ ){
If ($ pages = $ page ){
Echo "<span class = 'current'> $ pages </span> ";
} Else {
Echo "<a href = "? Page = $ pages $ pageurl "> $ pages </a> ";
}
}
If ($ page! = $ Pagenum ){
Echo "<a title =" Next "href =" ". $ _ SERVER ['php _ SELF ']."? Page = $ downpage $ pageurl ">></a> <a title =" Last page "href =" ". $ _ SERVER ['php _ SELF ']."? Page = $ pagenum $ pageurl ">></a> ";
} Else {
Echo "<span class = 'disabled '> </span> ";
}
// Jump
$ Javapage = <EOM
<Script language = "javascript">
Function web_page (targ, selObj, restore ){
Eval ("self" + ". location = '" + selObj. options [selObj. selectedIndex]. value + "'");
If (restore) selObj. selectedIndex = 0;
}
</Script>
EOM;
Echo $ javapage;
If ($ pageselect ){
Echo "jump to <select onchange =" web_page ('parent', this, 0) "name =" menu1 "> ";
For ($ pages = 1; $ pages <= $ pagenum; $ pages ++ ){
$ Selected = ($ pages = $ page )? "Selected =" selected "":"";
Echo "<option value =" ". $ _ SERVER ['php _ SELF ']."? Page = $ pages $ pageurl "$ selected> $ pages </option> ";
}
Echo "</select> page ";
}
}
?>