PHP list page display method _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.