Share the functional modules of php paging and the functional modules of php Paging
First paste a picture to see the effect
Paste the code.
<? Php $ localhost = "localhost"; $ username = "root"; $ password = "root"; $ db = "test"; // Information $ pagesize = 5; $ conn = mysql_connect ($ localhost, $ username, $ password); // link to the database if (! $ Conn) {echo "database link failed ". mysql_error ();} mysql_query ("set names 'utf8'"); // encode and convert $ db_select = mysql_select_db ($ db ); // select the 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 entries // total number of pages $ total = ceil ($ total_row/$ pagesize ); // current page $ page =@ _ GET ['P']? $ _ GET ['P']: 1; // lower limit of limit $ offset = ($ page-1) * $ pagesize; $ SQL = "select * from page order by id limit {$ offset}, {$ pagesize}"; $ result = mysql_query ($ SQL ); echo "<p> small module of PHP paging Code </p>"; 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 ;}// link jump; echo "
Key points:
1,
$sql = "select * from page order by id limit {$offset},{$pagesize}";
2,
Copy codeThe Code is as follows: echo "
These two points are the key points that reflect the paging technology and php Code Art ~
The above is all the content shared in this article. I hope you will like it.