Home > Article > Backend Development > PHP paging function module sharing_PHP tutorial
What I want to share with you here is a list paging function module that I made some time ago (the function module of PHP paging), which is very simple and practical. , recommended to friends in need for reference.
Post a picture first to see the effect
Please post the code
?
|
<🎜>$localhost = "localhost";<🎜>
<🎜>$username = "root";<🎜>
<🎜>$password = "root";<🎜>
<🎜>$db = "test"; //Information<🎜>
<🎜>$pagesize = 5;<🎜>
<🎜>$conn = mysql_connect($localhost,$username,$password); //Link database<🎜>
<🎜>if(!$conn){<🎜>
<🎜>echo "Database connection failed".mysql_error();<🎜>
<🎜>}<🎜>
<🎜>mysql_query("SET NAMES 'UTF8'"); //Encoding conversion<🎜>
<🎜>$db_select = mysql_select_db($db); //Select table<🎜>
<🎜>//Query the total number of 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 items<🎜>
<🎜>//Total number of pages<🎜>
<🎜>$total = ceil($total_row / $pagesize);<🎜>
<🎜>//Current page number<🎜>
<🎜>$page = @$_GET['p'] ? $_GET['p'] : 1;<🎜>
<🎜>//limit lower limit<🎜>
<🎜>$offset = ($page - 1)*$pagesize;<🎜>
<🎜> <🎜>
<🎜>$sql = "select * from page order by id limit {$offset},{$pagesize}";<🎜>
<🎜>$result = mysql_query($sql);<🎜>
<🎜>echo " Small module for PHP pagination code "; 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.
The code is as follows:
echo "
These two points are the key to embodying the art of paging technology and PHP code~
The above is all the content shared with you in this article. I hope you will like it.
TechArticle