Experience on realizing the Chinese Dream PHP development paging implementation code Page 1/3

WBOY
Release: 2016-07-29 08:48:25
Original
1370 people have browsed it

Project structure:

 php开发分页实现代码第1/3页

Running effect:

 php开发分页实现代码第1/3页

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 query string of 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); //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 Code:
$pagenav = "Display number " . ($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< /a> ";
else
$pagenav .= " Next page";
$pagenav .= "
Last page ";
//Drop-down Jump list, loop through all page numbers:
$pagenav .= "Go to page of $lastpg";
}
include("conn.php ");
$result=mysql_query("SELECT * FROM `test`");
$total=mysql_num_rows($result);
//Call pageft() to display 10 pieces of information per page (when using the default 20, You can omit this parameter) and use the URL of this page (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

Current page 1/3 123Next page

The above introduces the experience of realizing the Chinese Dream. PHP development paging implementation code page 1/3 includes the content of the experience of realizing the Chinese Dream. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!