Home >Backend Development >PHP Tutorial >PHP paging program implementation code for PHP development_PHP tutorial
It is relatively simple to implement paging in php+mysql. Just get the page and then For reference.
Project structure:
Operation effect:
Database connection code
The code is as follows | Copy code | ||||
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; } ?> |
Here is a more important sharing core function
The code is as follows | Copy code |
//URL analysis: //Start paging navigation bar code: $pagenav .= " Homepage ";
".$row[name]." | ".$row[sex]; } ?> |
list.php
Database query records and generate sql query statements
The code is as follows
|
Copy code | ||||||||
include("conn.php"); <🎜>
$pagesize=5; 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[page]){ <🎜>
$pageval=$_GET[page]; <🎜>
$page=($pageval-1)*$pagesize; <🎜>
$page.=',';<🎜>
} <🎜>
if($num > $pagesize){
if($pageval<=1)$pageval=1;<🎜>
echo "Total $num items". 21 " Previous page Next page";
}
$SQL="SELECT * FROM `test` limit $page $pagesize ";
$query=mysql_query($SQL);
while($row=mysql_fetch_array($query)){
echo " ".$row[name]." | ".$row[sex]; } ?> Paging formula: (current page number - 1) * number of items per page, number of items per page
Summary: No matter what program is developed, it is divided into one. The original method is to take N items starting from Take 5 out of 1. Let’s introduce the core code. Here we get the paging number, and the Xpagesize code is as follows
|