Code sharing for a typical PHP paging instance

Source: Internet
Author: User
A typical PHP paging instance code sharing will surely be used by friends who are learning php, mainly for understanding their ideas. The code is as follows:




Php make page list
















































';
$ Key. = "$ page/$ pages"; // page
If ($ page! = 1 ){
$ Key. = "first page"; // first page
$ Key. = "previous page"; // Previous Page
} Else {
$ Key. = "first page"; // first page
$ Key. = "previous page"; // Previous Page
}
If ($ pages> $ page_len ){
// If the current page is less than or equal to the left offset
If ($ page <= $ pageoffset ){
$ Init = 1;
$ Max_p = $ page_len;
} Else {// if the current page is greater than the left offset
// If the right offset of the current page number exceeds the maximum page number
If ($ page + $ pageoffset >=$ pages + 1 ){
$ Init = $ pages-$ page_len + 1;
} Else {
// Calculation when both the left and right offsets exist
$ Init = $ page-$ pageoffset;
$ Max_p = $ page + $ pageoffset;
}
}
}
For ($ I = $ init; $ I <= $ max_p; $ I ++ ){
If ($ I = $ page ){
$ Key. = ''. $ I .'';
} Else {
$ Key. = "". $ I ."";
}
}
If ($ page! = $ Pages ){
$ Key. = "next page"; // Next page
$ Key. = "Last page"; // Last Page
} Else {
$ Key. = "next page"; // Next page
$ Key. = "Last page"; // Last Page
}
$ Key. ='






/** Created on 2010-4-17** Order by Kove Wong*/$ Link = MySQL_connect ('localhost', 'root', 'haoxiazai1987 ');Mysql_select_db ('pagelist ');Mysql_query ('set names gbk ');$ Page_size = 10;$ Result = mysql_query ('select * from v_char ');$ Count = mysql_num_rows ($ result );$ Page_count = ceil ($ count/$ Page_size );$ Init = 1;$ Page_len = 7;$ Max_p = $ page_count;$ Pages = $ page_count;// Determine the current page numberIf (empty ($ _ GET ['Page']) | $ _ GET ['Page'] <0 ){$ Page = 1;} Else {$ Page = $ _ GET ['Page'];}$ Offset = $ Page_size * ($ page-1 );$ SQL = "select * from v_char limit $ offset, $ Page_size ";$ Result = mysql_query ($ SQL, $ link );While ($ row = mysql_fetch_array ($ result )){?> }$ Page_len = ($ page_len % 2 )? $ Page_len: $ pagelen + 1; // Number of page numbers$ Pageoffset = ($ page_len-1)/2; // page number offset between left and right$ Key ='';?>
ID Article title







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.