Implement the "Previous Page" and "next page" buttons

Source: Internet
Author: User

Introduction: This is a detailed page for implementing the "Previous Page" and "next page" buttons. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 327666 'rolling = 'no'>

<? PHP
// This example is taken from phpbuilder.com.
// A little Translation
// <Sprming@netease.com>

$ Limit = 20; // number of lines displayed per page
$ Numresults = mysql_query ("select * from table where your conditional here order by whatever"); // replace it with the required SQL statement
$ Numrows = mysql_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_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_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 "<a href = \" $ php_self? Offset = $ prevoffset \ "> previous page </a> & nbsp; \ n ";
}

// 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 "<a href = \" $ php_self? Offset = $ newoffset \ "> $ I </a> & nbsp; \ n ";
}

// Check to see if last page
If (! ($ Offset/$ limit) ==$ pages) & $ pages! = 1 ){
// Not last page so give next link
$ Newoffset = $ Offset + $ limit;
Print "<a href = \" $ php_self? Offset = $ newoffset \ "> next page </a> <p> \ n ";
}

?>

More articles about "Previous Page" and "next page" buttons

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/327666.html pageno: 12.

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.