A few days ago just learned how to use PHP's own API to operate the MySQL database, just take a few pages of this small case practice hands.
There are many algorithms for paging, and here's just a simple one.
The principle of paging:
First get the total number of rows $row_num, divided by the number of rows per page $page_size, rounding up the total number of pages $page_num.
The first record that is easy to get page one is the whole table ($page-1) *page_size records, recorded as $offset
(Note: The row index starts at 0)
Then apply the MySQL limit keyword to get each page of the record results displayed.
SELECT * FROM test limit offset, page_size;
Specific implementation code: two files conn.php indes.php
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/88/44/wKiom1fs0TigiqMMAAASVZgoU3g654.jpg-wh_500x0-wm_3 -wmp_4-s_1641262107.jpg "title=" 1.jpg "alt=" Wkiom1fs0tigiqmmaaasvzgou3g654.jpg-wh_50 "/>
/*conn.php*/<?php$mysqli = new mysqli ("localhost", "root "," 123456 "," MyDB ") or die (" Database connection failed! ". $mysqli->errno);
/*index.php*/<?phpinclude_once ("conn/conn.php"), $page = $_get["page"];if ($page == "") { $page = 1;} if (Is_numeric ($page)) { $page _size = 4; $res = $mysqli->query ("Select * from test"); $row _count = $res->num_rows; $page _num = ceil ($row _count / $page _size); $offset = ($page - 1) * $page _size; $res = $mysqli->query ("select * from test limit $offset, $page _size "); while ($row = $res->fetch_assoc ()) { echo "<table><tr>"; echo "<td>". $row ["id"]. " </td> "; echo "</table>"; }}echo "Total". $page _num. " Page record ";echo " <br> "if ($page != 1) { echo " <a href= Index.php?page=1> Home </a> "//index.php path without quotation marks can also echo " <a href= Index.php?page= ". ($page - 1). " > Prev </a> ";//If the expression is not a direct variable, it must be calculated after use. Connection}for ($i =1; $i <= $page _num; $i + +) { echo "<a href=index.php?page=". $i. " > Page $i </a> ";} if ($page < $page _num) { echo "<a href=index.php?page=". ( $page + 1). " > Next </a> "; echo " <a href=index.php?page= $page _num> last </a> ";}
This article is from the "thick Product Thin Hair" blog, please make sure to keep this source http://joedlut.blog.51cto.com/6570198/1857808
Getting Started with PHP (16) using MYSQLI to implement simple paging