Paging function A useful paging function

Source: Internet
Author: User
Copy CodeThe code is as follows:


My original code, the master seems, perhaps the process clumsy point, but very practical. Look at the top.
/*---------------------------------------------------------------//
* Function Description: Paging function page ($sql, $pagesize = "30")
* $SQL query statement (except limit, can be sorted or conditional)
* such as SELECT * from Stu where time between "1" and "30";
* $pagesize the number of display bars per page
* # # can output the value of the array $arr, described as follows:
* $arr ["First"] home page and address
* $arr ["page_pre"] previous page and address
* $arr ["All"] when pages and total pages
* $arr ["page_next"] next page and address
* $arr ["Last"] end and address
* $arr ["pagelist"] page list and address, display the current page before and after 4 page list
* $arr ["query"] statement $arr ["query"] = mysql_query ($sql)
* $arr ["nums"] Total records
* 2006.09.06 by Kevin qq:84529890
//----------------------------------------------------------------*/
Function page ($sql, $pagesize = "30") {
Global $arr, $PHP _self;
$query = mysql_query ($sql);
$num = mysql_num_rows ($query);
$pagecount = Ceil ($num/$pagesize);
$page = $_get["page"];
if (! $page) $page = 1;
if ($page > $pagecount) $page = $pagecount;
$offset = ($page-1) * $pagesize;
$sql. = "Limit $offset, $pagesize";
$arr ["query"] = mysql_query ($sql);
if ($page >1) {
$page _pre = $page-1;
$page _url = $PHP _self. "Page=". $page _pre;
$arr ["page_pre"] = "Previous page |\n";
}
if ($page < $pagecount) {
$page _next = $page +1;
$page _url = $PHP _self. "Page=". $page _next;
$arr ["page_next"] = "| next \ n";
}
$arr ["all"] = "". $page. " /". $pagecount. "Page \ n";
$arr ["First"] = "Home \n|";
$arr ["last"] = "| end \ n";
$plfr
if ($page <=5 && $page >=1) {
for ($i =1; $i <=9; $i + +) {
$plfront. = "". $i. "";
}
}elseif ($page >5 && $page < $pagecount-5) {
for ($i = $page-4; $i < $page +5; $i + +) {
$plfront. = "". $i. "";
}
}else{
for ($i = $pagecount-8; $i <= $pagecount; $i + +) {
$plfront. = "". $i. "";
}
}
$arr ["pagelist"] = $plfront. " ";
$arr ["nums"] = $num;
}

The above describes a paging function, a useful paging function, including the content of the paging function, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.