Share PHP page function module, PHP paging function module
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 '"); Encoding 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 bars//Total pages $total = ceil ($total _row/$pagesize); Current page $page = @$_get[' P ']? $_get[' P ']: 1; Limit limit $offset = ($page-1) * $pagesize; $sql = "SELECT * from page order by ID limit {$offset},{$pagesize}"; $result = mysql_query ($sql); echo "PHP pagination code for small modules
"; 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; }//do link jump; echo "
Previous page 丨 next page
"; Mysql_free_result ($result); Mysql_close ($conn);? >
Key points:
1.
$sql = "SELECT * from page order by ID limit {$offset},{$pagesize}";
2.
Copy the Code code as follows: Echo "
Previous page 丨 next page
";
These two points are the key to the art of paging technology and PHP code-
The above mentioned is this article to share all the content, I hope you can enjoy.
http://www.bkjia.com/PHPjc/1017888.html www.bkjia.com true http://www.bkjia.com/PHPjc/1017888.html techarticle Share PHP paging function module, PHP paging function module first put a picture to see the effect of the code bar PHP $localhost = "localhost"; $username = "root"; $password = "root"; $db = "T ...