Implement the previous page and Next button _php tutorial

Source: Internet
Author: User
Tags prev
This example is excerpted from phpbuilder.com
Slightly translated
//

$limit = 20; Number of lines displayed per page
$numresults =mysql_query ("select * from TABLE where YOUR CONDITIONAL here Order by WHATEVER");//Replace the SQL statement you need
$numrows =mysql_num_rows ($numresults);

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

Get query Results
$result =mysql_query ("Select Id,name,phone".
"From TABLE where YOUR CONDITIONAL here".
"ORDER by WHATEVER limit $offset, $limit");

Show Query Results now
while ($data =mysql_fetch_array ($result)) {
Insert the result you want to display here and the style
}

Display button

if ($offset!) =1) {//Bypass PREV link if offset is 1
$prevoffset = $offset-20;
print "prev \ n";
}

Number of pages calculated
$pages =intval ($numrows/$limit);

$pages now contains int of pages needed unless there are a remainder from division
if ($numrows% $limit) {
have remainder so add one page
$pages + +;
}

for ($i =1; $i <= $pages; $i + +) {//Show pages
$newoffset = $limit * ($i-1);
print "$i \ n";
}

Check to see if last page
if (! ( ($offset/$limit) = = $pages) && $pages!=1) {
Not last page so give NEXT link
$newoffset = $offset + $limit;
Print "Next page

\ n ";
}

?>


http://www.bkjia.com/PHPjc/315557.html www.bkjia.com true http://www.bkjia.com/PHPjc/315557.html techarticle PHP//This example is from phpbuilder.com//A little translation//sprming@netease.com $limit = 20;//The number of rows displayed per page $numresults =mysql_query (SELECT * FROM TABLE where YOUR CONDITIONAL here ...

  • 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.