PHP Development Paging Implementation Code 1th/3 Page _php Tutorial

Source: Internet
Author: User
Project Structure:

Operating effect:

conn.php
Copy CodeThe code is as follows:
$conn = @ mysql_connect ("localhost", "root", "") or Die ("Database link error");
mysql_select_db ("form", $conn);
mysql_query ("Set names ' GBK '"); Use GBK Chinese code;
Replace space, enter
function Htmtocode ($content) {
$content = Str_replace ("\ n", "
", Str_replace (" "," ", $content));
return $content;
}
?>

page.php
Copy CodeThe code is as follows:
1 2
3 function _pageft ($totle, $displaypg = A, $url = ") {
4
5 Global $page, $firstcount, $pagenav, $_server;
6
7 $GLOBALS ["displaypg"] = $DISPLAYPG;
8
9 if (! $page)
$page = 1;
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) {
$url _query = ereg_replace ("(^|&) page= $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, 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 ";
}
Include ("conn.php");
$result =mysql_query ("SELECT * from ' Test ');
$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, 5);
Echo $pagenav;
$result =mysql_query ("SELECT * from ' Test ' limit $firstcount, $displaypg");
while ($row =mysql_fetch_array ($result)) {
echo " . $row [name]. "| ". $row [Sex];
}
?>

list.php
[code]
!--? PHP include ("conn.php");
$pagesize = 5;
$url =$_server["Request_uri"];
$url =parse_url ($url);
$url = $url [path];
$numq =mysql_query ("SELECT * from ' Test ');
$num = mysql_num_rows ($NUMQ);
if ($_get

http://www.bkjia.com/phpjc/325347.html www.bkjia.com true http://www.bkjia.com/phpjc/325347.html techarticle Project structure: Run Effect: conn.php copy code code as follows:? php $conn = @ mysql_connect ("localhost", "root", "") or Die ("Database link error"); mysql_select_db ("form", $ ...

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