A very good PHP Flip Class _php Tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
/*
* Created on 2007-6-8
* Programmer:alan, Msn-haowubai@hotmail.com
* bkjia.com Develop a project Php-mysql-apache
* Window-preferences-phpeclipse-php-code Templates
*/
To avoid errors caused by repeating the inclusion of a file, add a condition that determines whether the function exists:
if (!function_exists (Pageft)) {
Define the function Pageft (), the meaning of the three parameters is:
$totle: Total information;
$DISPLAYPG: The number of messages displayed per page, which is set to default is 20;
$url: The link in the pager is the same as this one except for adding different query Information "page".
The default value should be set to the page URL (that is, $_server["Request_uri"]), but the default value can only be constant to the right, so the default value is set to an empty string, which is then set to the page URL inside the function.
function Pageft ($totle, $displaypg =20, $url = ") {

Define several global variables:
$page: current page number;
$firstcount: The starting item of the (database) query;
$pagenav: the page navigation bar code, inside the function does not output it;
$_server: Read this page url "$_server[" Request_uri "]" must.
Global $page, $firstcount, $pagenav, $_server;

For the outside of the function to have access to the "$DISPLAYPG" here, it is also set as a global variable. Note that when a variable is redefined as a global variable, the original value is overwritten, so it is re-assigned.
$GLOBALS ["Displaypg"]= $displaypg;

if (! $page) $page = 1;

If you use the default, or null value, for the value of the page, the URL is assigned:
if (! $url) {$url =$_server["Request_uri"];}

URL Analysis:
$parse _url=parse_url ($url);
$url _query= $parse _url["Query"]; Query string to take out the URL separately
if ($url _query) {
Because the URL may contain the page number information, we want to remove it, in order to add the new page number information.
Regular expressions are used here, please refer to "Regular Expressions in PHP"
$url _query=ereg_replace ("(^|&) page= $page", "", $url _query);

Replace the query string for the processed URL with the query string for the original URL:
$url =str_replace ($parse _url["Query"], $url _query, $url);

Add page query information after URL, but to assign value:
if ($url _query) $url. = "&page"; else $url. = "page";
}else {
$url. = "? page";
}

Page Count:
$LASTPG =ceil ($totle/$DISPLAYPG); Last page, also the total number of pages
$page =min ($LASTPG, $page);
$PREPG = $page-1; Previous page
$NEXTPG = ($page = = $lastpg? 0: $page + 1); Next page
$firstcount = ($page-1) * $DISPLAYPG;

Start Page navigation bar code:
$pagenav = "Show ". ($totle? ($firstcount + 1): 0). "- ". Min ($firstcount + $DISPLAYPG, $totle)."Records, a total of $totle records ";

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

$pagenav. = "Home";
if ($PREPG) $pagenav. = "front page"; else $pagenav. = "front page";
if ($NEXTPG) $pagenav. = "Back Page"; else $pagenav. = "Back Page";
$pagenav. = "Last";

Drop-down Jump List, looping through all page numbers:
$pagenav. = "To \ n "; for ($i =1; $i <= $lastpg; $i + +) {if ($i = = $page) $pagenav. = "$i \ n "; else $pagenav. = "$i \ n "; } $pagenav. = "Page, total $lastpg page ";
}
}
?>


/*
(Previous procedure slightly)

Include ("pageft.php"); Include "pageft.php" file
Total number of information obtained
$result =mysql_query ("SELECT * from MyTable");
$total =mysql_num_rows ($result);
Call Pageft (), displaying 10 messages per page (this parameter can be omitted using the default 20 o'clock), using the page URL (default, so omitted).
Pageft ($total, 10);
The global variables that are generated now come in handy:
$result =mysql_query ("select * FROM MyTable limit $firstcount, $displaypg");
while ($row =mysql_fetch_array ($result)) {
(List content slightly)
}

Output paging navigation bar code:
Echo $pagenav;

(later procedure slightly)
*/
?>

http://www.bkjia.com/PHPjc/320072.html www.bkjia.com true http://www.bkjia.com/PHPjc/320072.html techarticle Copy the code as follows: PHP/* * Created on 2007-6-8 * Programmer:alan, Msn-haowubai@hotmail.com * php100.com Develop a Proje CT Php-mysql-apache * window-preferences ...

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