Project structure:
Running effect:
conn.phpCopy 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 ;
}
?>
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 "
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.