Copy Code code as follows:
<?php
Header ("Content-type:text/html;charset=utf-8");
Database connection
$conn = mysql_connect ("localhost", "root", "a") or Die ("Not connnected:". Mysql_error ());
mysql_select_db ("Test", $conn);
mysql_query ("Set names UTF8");
How many rows of data are there in a query
$sql 1 = "SELECT count (*) from user";
$ret 1 = mysql_query ($sql 1);
$row 1 = mysql_fetch_row ($ret 1);
$tot = $row 1[0];
How many rows of data per page
$length = 5;
Total pages
$totpage = Ceil ($tot/$length);
Current page
$page = @$_get[' P ']? $_get[' P ']: 1;
Limit lower Limit
$offset = ($page-1) * $LENGTH;
echo "<center>";
echo "echo "<table width= ' 700px ' border= ' 1px ' >";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>USER</th>";
echo "<th>PASS</th>";
echo "</tr>";
Display the queried data in a table
$sql 2 = "SELECT * from user order by ID limit {$offset}, {$length}";
$ret 2 = mysql_query ($sql 2);
while ($row 2 = MYSQL_FETCH_ASSOC ($ret 2)) {
echo "<tr>";
echo "<td>{$row 2[' id ']}</td><td>{$row 2[' name ']}</td><td>{$row 2[' pass ']}</td > ";
echo "</tr>";
}
echo "</table>";
Previous page and next page
$prevpage = $page-1;
if ($page >= $totpage) {
$nextpage = $totpage;
} else {
$nextpage = $page + 1;
}
Jump
echo "echo "</center>";
Core point:
<1> "$sql 2 =" SELECT * from user order by ID limit {$offset}, {$length} ";", $offset, $length, and the relationship between pages.
<2> the previous page and the next page to get the way, as well as the critical point.