一个简单php和mysql数据分页程序有需要的朋友可参考一下。
代码如下 复制代码
$lastpage) { // if it is greater than $lastpage
$pn = $lastpage; // force it to be $lastpage's value
}
// this creates the numbers to click in between the next and back buttons
// this section is explained well in the video that accompanies this script
$centerpages = ;
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
$centerpages .= ' ' . $pn . ' ';
$centerpages .= ' ' . $add1 . ' ';
} else if ($pn == $lastpage) {
$centerpages .= ' ' . $sub1 . ' ';
$centerpages .= ' ' . $pn . ' ';
} else if ($pn > 2 && $pn $centerpages .= ' ' . $sub2 . ' ';
$centerpages .= ' ' . $sub1 . ' ';
$centerpages .= ' ' . $pn . ' ';
$centerpages .= ' ' . $add1 . ' ';
$centerpages .= ' ' . $add2 . ' ';
} else if ($pn > 1 && $pn $centerpages .= ' ' . $sub1 . ' ';
$centerpages .= ' ' . $pn . ' ';
$centerpages .= ' ' . $add1 . ' ';
}
// this line sets the limit range... the 2 values we place to choose a range of rows from database in our query
$limit = 'limit ' .($pn - 1) * $itemsperpage .',' .$itemsperpage;
// now we are going to run the same query as above but this time add $limit onto the end of the sql syntax
// $sql2 is what we will use to fuel our while loop statement below
$sql2 = mysql_query(select id, firstname, country from mytable order by id asc $limit);
//////////////////////////////// end adam's pagination logic ////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// adam's pagination display setup /////////////////////////////////////////////////////////////////////
$paginationdisplay = ; // initialize the pagination output variable
// this code runs only if the last page variable is ot equal to 1, if it is only 1 page we require no paginated links to display
if ($lastpage != 1){
// this shows the user what page they are on, and the total number of pages
$paginationdisplay .= 'page ' . $pn . ' of ' . $lastpage. ' ';
// if we are not on page 1 we can place the back button
if ($pn != 1) {
$previous = $pn - 1;
$paginationdisplay .= ' back ';
}
// lay in the clickable numbers display here between the back and next links
$paginationdisplay .= '' . $centerpages . '';
// if we are not on the very last page we can place the next button
if ($pn != $lastpage) {
$nextpage = $pn + 1;
$paginationdisplay .= ' next ';
}
}
///////////////////////////////////// end adam's pagination display setup ///////////////////////////////////////////////////////////////////////////
// build the output section here
$outputlist = '';
while($row = mysql_fetch_array($sql2)){
$id = $row[id];
$firstname = $row[firstname];
$country = $row[country];
$outputlist .= '
' . $firstname . '' . $country . ' ';
} // close while loop
?>
adam's pagination
total items:
效果
page 6 of 39 back 4 5 6 7 8 next
http://www.bkjia.com/phpjc/633091.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/633091.htmltecharticle一个简单php和mysql数据分页程序有需要的朋友可参考一下。 代码如下 复制代码 ?php // adam's custom php mysql pagination tutorial and script // you have to...