Home > Backend Development > PHP Tutorial > PHP development paging implementation code page 1/3_PHP tutorial

PHP development paging implementation code page 1/3_PHP tutorial

WBOY
Release: 2016-07-21 15:19:16
Original
1047 people have browsed it

Project structure:

Operation effect:

conn.php
Copy code The 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 encoding;
//Replace spaces and enter key
function htmtocode($content) {
$content = str_replace("n", "
", str_replace(" ", " ", $content));
return $content;
}
?>

page.php
Copy code The code is as follows:

1 2
3 function _PAGEFT($totle, $displaypg = 20, $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"]; //Get the URL query string 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); //The 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 paging navigation bar code:
$pagenav = "Display the " . ($totle ? ($firstcount +1) : 0) . "- " . min($firstcount + $displaypg, $totle) ​​. " records, total $totle records";
//If there is only one page, jump out of the function:
if ($lastpg <= 1)
return false;
$pagenav .= " Homepage ";
if ($ prepg)
$pagenav .= " Previous page ";
else
$pagenav .= " Previous page";
if ($nextpg)
$pagenav .= " Next page ";
else
$pagenav .= " Next page";
$pagenav .= " Last page ";
//Pull down jump list, loop through all page numbers :
$pagenav .= "Go to pages of $lastpg";
}
include("conn.php");
$result=mysql_query("SELECT * FROM `test`");
$total=mysql_num_rows($result);
//Call pageft(), display 10 pieces of information per page (when using the default 20, you can omit this parameter), use this page URL (default, so omit it ).
_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]
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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325347.htmlTechArticleProject structure: Running effect: conn.php Copy the code as follows: ?php $conn = @ mysql_connect("localhost ", "root", "") or die("Database link error"); mysql_select_db("form", $...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template