PHP MySQL Paging function

Source: Internet
Author: User
Tags php mysql

+-----------------------------------------------------------------------
| File Summary: Pagination display function
| File name: page.php
| Date Created: 2010-5-20
+-----------------------------------------------------------------------
*/
function _pageft ($totle, $displaypg = $url = ') {

Global $page, $firstcount, $pagenav, $_server;

$globals ["displaypg"] = $DISPLAYPG;

if (! $page)
$page = 1;
if (! $url) {
$url = $_server["Request_uri"];
}

  //url Analysis:
   $parse _url = Parse_url ($url);
   $url _query = $parse _url["Query "]; Query string
  if ($url _query) {
    $url _query = Preg_replace ("/(^|&) page=$" for individual removal of URLs page/"," ", $url _query);
    $url = str_replace ($parse _url["Query"), $url _query, $url);
   if ($url _query)
     $url. = "&page";
   else
     $url. = "page";
  } else {
    $url. = "? page";
  }
   $lastpg = ceil ($totle /$DISPLAYPG); Last page, is also the total number of pages
   $page = min ($lastpg, $page);
   $PREPG = $page-1;//prev
  $ NEXTPG = ($page = = $LASTPG 0: $page + 1); Next page
   $firstcount = ($page-1) * $DISPLAYPG;

To start the pager bar code:
$pagenav = "Show <b>". ($totle? ($firstcount + 1): 0). "</b>-<b>". Min ($firstcount + $DISPLAYPG, $totle). "</b> Records &nbsp;&nbsp; total <font color= ' red ' > $totle </font> message";

If only one page jumps out of the function:
if ($LASTPG <= 1)
return false;

$pagenav. = "<a href= ' $url =1 ' > Home </a>";
if ($PREPG)
$pagenav. = "<a href= ' $url = $prepg ' > front page </a>";
Else
$pagenav. = "front page";
if ($NEXTPG)
$pagenav. = "<a href= ' $url = $nextpg ' > Back page </a>";
Else
$pagenav. = "Back Page";
$pagenav. = "<a href= ' $url = $lastpg ' > Last </a>";

Drop-down Jump List, looping through all page numbers:
$pagenav. = "to <select class= ' border:1px solid #98ccfa; ' name= ' topage ' size= ' 1 ' onchange= ' window.location= ' $url =" + This.value ' >n ';
for ($i = 1; $i <= $lastpg; $i + +) {
if ($i = = $page)
$pagenav. = "<option value= ' $i ' selected> $i </option>n";
Else
$pagenav. = "<option value= ' $i ' > $i </option>n";
}
$pagenav. = "</select> page &nbsp;&nbsp;&nbsp; total <font color= ' red ' > $lastpg </font> page";
}
?>

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.