Implement "previous page" and "Next Page button"

Source: Internet
Author: User
& Lt ;? Php (as the mainstream development language) & nbsp; // This example is taken from php (as the mainstream development language) builder.com & nbsp; // slightly translated & nbsp; // & lt; sprming@netease.com & gt; & nbsp; & #36; limit20; // The number of lines displayed per page // This example is taken from php (as the mainstream development language) builder.com.
// A little translation
//

$ Limit = 20; // number of lines displayed per page
$ Numresults = MySQL (the best combination with PHP) _ query ("select * from TABLE where your conditional here order by WHATEVER"); // replace it with the SQL statement you need
$ Numrows = MySQL (the best combination with PHP) _ num_rows ($ numresults );

// Next determine if offset has been passed to script, if not use 0
If (empty ($ offset )){
$ Offset = 1;
}

// Obtain the query result
$ Result = MySQL (the best combination with PHP) _ query ("select id, name, phone ".
"From TABLE where your conditional here ".
"Order by WHATEVER limit $ offset, $ limit ");

// The query result is displayed now.
While ($ data = MySQL (the best combination with PHP) _ fetch_array ($ result )){
// Insert the result and style you want to display here
}

// Display button

If ($ offset! = 1) {// bypass PREV link if offset is 1
$ Prevoffset = $ offset-20;
Print "(as the mainstream development language) _ SELF? Offset = $ prevoffset "> Previous Page ";
}

// Calculate the number of pages
$ Pages = intval ($ numrows/$ limit );

// $ Pages now contains int of pages needed unless there is a remainder from division
If ($ numrows % $ limit ){
// Has remainder so add one page
$ Pages ++;
}

For ($ I = 1; $ I <= $ pages; $ I ++) {// display the page number
$ Newoffset = $ limit * ($ i-1 );
Print "(as the mainstream development language) _ SELF? Offset = $ newoffset "> $ I ";
}

// Check to see if last page
If (! ($ Offset/$ limit) ==$ pages) & $ pages! = 1 ){
// Not last page so give NEXT link
$ Newoffset = $ offset + $ limit;
Print "(as the mainstream development language) _ SELF? Offset = $ newoffset "> Next page

";
}

?>


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.