PHP paging instance code _ PHP Tutorial

Source: Internet
Author: User
PHP paging instance code. PHP paging instance code! DOCTYPEhtmlPUBLIC-W3CDTDXHTML1.0TransitionalENwww.w3.orgTRxhtml1DTDxhtml1-transitional.dtdhtmlxmlnswww.w3.org1999xhtmlhe PHP paging instance code





Php Tutorial make page list















$ 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 number
If (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 )){
?>







$ Key ='






';
$ 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 tutorial _ select_db ('pagelist ');Mysql_query ('set names gbk '); }$ 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 ';?>
ID Article title








Success! 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 he...

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.