PHP list page display method .! DOCTYPEhtmlPUBLIC-W3CDTDXHTML1.0TransitionalENwww.w3.orgTRxhtml1DTDxhtml1-transitional.dtdhtmlxmlnswww.w3.org1999xhtmlheadmetahttp-equivCon
Untitled Document
Id
Value
$ Link = mysql_connect ("localhost", "root", ""); // connect to the database
Mysql_select_db ("cs"); // select the database
Mysql_query ("set names UTF-8"); // sets the database character encoding to Chinese.
$ SQL = mysql_query ("select * from persons ");
$ Pagesize = 5; // Number of Entries displayed
$ Sum = mysql_num_rows ($ SQL); // you can specify the total number of data records.
$ Count = ceil ($ sum/$ pagesize); // you can find the total number of pages.
$ Pages = $ count; // display the last page
$ Init = 1;
$ Page_len = 7;
$ Max_p = $ count;
If (empty ($ _ GET ["page"]) | $ _ GET ["page"] <0 ){
$ Page = 1;
} Else {
$ Page = $ _ GET ["page"];
}
$ Off = ($ page-1) * $ pagesize; // obtain the first data queried by the database.
$ He = mysql_query ("select * from persons limit $ off, $ pagesize"); // The pagesize rule is displayed starting from off.
Echo "total". $ sum. "data entries ";
While ($ row = mysql_fetch_array ($ he )){
Echo "";
Echo "". $ row ['id']. "";
Echo "". $ row ['firstname']. "";
Echo "";
}
?>
$ Page_len = ($ page_len % 2 )? $ Page_len: $ page_len + 1; // if the remainder is 1, it is true. if it is 0, it is false.
$ Pageoffset = ($ page_len-1)/2; // page offset
$ Key = "";
If ($ page! = 1 ){
$ Key. = "first page ";
$ Key. = "previous page ";
} Else {
$ Key. = "first page ";
$ Key. = "previous page ";
}
If ($ pages> $ page_len ){
If ($ page <= $ pageoffset ){
$ Init = 1;
$ Max_p = $ page_len;
} Else {
If ($ page + $ pageoffset >=$ pages + 1 ){
$ Init = $ pages-$ page_len + 1;
} Else {
$ Init = $ page-$ pageoffset;
$ Max_p = $ page + $ pageoffset;
}
}
}
For ($ I = $ init; $ I <= $ max_p; $ I ++ ){
If ($ I = $ page ){
$ Key. = "[". $ I. "]";
} Else {
$ Key. = "$ I ";
}
}
If ($ I-1! = $ Page ){
$ Key. = "next page ";
$ Key. = "Last page ";
} Else {
$ Key. = "next page ";
$ Key. = "Last page ";
}
Echo "";
Echo "". $ key ."";
Echo "";
?>
Http://www.bkjia.com/PHPjc/820419.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/820419.htmlTechArticle! 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 = Con...