Put a picture first to see the effect
Just post the code.
<?php $localhost = "localhost";
$username = "root";
$password = "root"; $db = "Test";
Information $pagesize = 5; $conn = mysql_connect ($localhost, $username, $password);
Link database if (! $conn) {echo database link failed. mysql_error (); } mysql_query ("SET NAMES ' UTF8 '"); Code conversion $DB _select = mysql_select_db ($db);
Select Table//Total number of query records $total _sql = "Select COUNT (*) from page";
$total _result = mysql_query ($total _sql);
$total _row_arr = mysql_fetch_row ($total _result); $total _row = $total _row_arr[0];
Total number of articles//total pages $total = ceil ($total _row/$pagesize); Current number of pages $page = @$_get[' P ']?
$_get[' P ']: 1;
Limit lower bound $offset = ($page-1) * $pagesize;
$sql = "SELECT * from page order by ID limit {$offset},{$pagesize}";
$result = mysql_query ($sql);
echo "Small module </p> of <p>php paging code";
echo "<table border=1 cellspacing=0 width=60% align=center>";
echo "<tr><td>ID</td><td>NAME</td></tr>"; while ($row = Mysql_fetch_assoc ($result)) {$id = $row [' ID'];
$name = $row [' name ']; echo "<tr><td>". $id. " </td><td> ". $name."
</td></tr> ";
echo "</table>";
Previous page, next page $pageprev = $page-1;
if ($page > $total) {$pagenext = $total;
else{$pagenext = $page +1; //do link jumps; echo "
Key points:
1,
$sql = "SELECT * from page order by ID limit {$offset},{$pagesize}";
2,
Copy Code code as follows:
echo "
These two points are key to reflect the pagination technology and PHP code art Place ~
The above is the article to share all the content, I hope you can enjoy.