PHP abbreviated digital paging display code

Source: Internet
Author: User
PHP Simple Digital Paging display code
 $totalpages) {//Set current page to the last page $currentpage = $totalpages;}//End if//If current page was less than  First Page...if ($currentpage < 1) {//Set current page to first page $currentpage = 1;}//End if//The offset of The list, based on current page $offset = ($currentpage-1) * $rowsperpage;//Get the info from the db/* $sql = "Select ID, number from numbers LIMIT $offset, $rowsperpage "; $result = mysql_query ($sql, $conn) or Trigger_error (" SQL ", E_user_err OR); */$sql = "SELECT id, number from numbers LIMIT $offset, $rowsperpage"; Echo $sql. "
";//While there is rows to be fetched.../*while ($list = Mysql_fetch_assoc ($result)) {//Echo data echo $list [' ID '] . " : " . $list [' Number ']. "
";} End while*//****** Build the pagination links ******///range of num links to Show$range = 3;//if not on page 1, Don ' T show back Linksif ($currentpage > 1) {//Show << link to go back to Page 1 echo "<<"; Get previous page num $prevpage = $currentpage-1; Show < link to go 1 page echo "<";} End If//loop to show links to range of pages around current pagefor ($x = ($currentpage-$range); $x < ($current Page + $range) + 1); $x + +) {//If it ' s a valid page number ... if (($x > 0) && ($x <= $totalpages)) {//If we ' re on cur Rent page ... if ($x = = $currentpage) {//' highlight ' it but don ' t make a link echo "[$x] "; If not current page ...} else {//Make it a link echo "$x"; }//End else}//End If}//end for//if not on last page, show forward and last page links I F ($currentpage! = $totalpages) {//Get next page $nextpage = $currentpage + 1; echo forward link for next page echo ">"; echo forward link for lastpage echo ">>";} End if/****** End Build pagination links ******/?> <title>Page out</title>

Excerpt from: http://www.phpfreaks.com/tutorial/basic-pagination

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