Share The php paging function module and the php paging function module. Share The php paging function module. The php paging function module will first paste a picture to see the effect of the code. php $ localhostlocalhost; $ usernameroot; $ passwordroot; $ dbt share the php paging function module, php paging function module
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"Small module of PHP paging code
"; Echo"
"; Echo"
ID |
NAME |
"; While ($ row = mysql_fetch_assoc ($ result) {$ id = $ row ['id']; $ name = $ row ['name']; echo"
". $ Id ." |
". $ Name ." |
";} Echo"
"; // Previous page, next page $ pageprev = $ page-1; if ($ page >$ total) {$ pagenext = $ total ;} else {$ pagenext = $ page + 1;} // Link jump; echo "previous page next"; mysql_free_result ($ result); mysql_close ($ conn);?>
Key points:
1,
$sql = "select * from page order by id limit {$offset},{$pagesize}";
2,
The code is as follows: echo "previous page previous next page ";
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.
Paste a picture to see the effect. php $ localhost = "localhost"; $ username = "root"; $ password = "root "; $ db = "t...