Implementing the previous page and next page buttons
Source: Internet
Author: User
KeywordsImplementing the previous page and next page buttons
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 + +;
}
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
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.