<?php /**1,传入页码**/ $page = $_GET["p"]; /**2,根据页码取出数据:php->mysql的处理**/ $host = "localhost"; $username = "root"; $password = "123456789"; $db = "bbs2"; //连接数据库 $conn = mysql_connect($host,$username,$password); if (!$conn) { // echo "数据库连接失败"; exit; } //选择要操作的数据库 mysql_select_db($db); //设置数据库编码格式 mysql_query("SET NAMES UTF8"); //编写sql获取分页数据SELECT * FROM 表名 LIMIT 起始位置,显示条数 $sql = "select * from test limit ".($page-1) * 10 .",10 "; //把sql语句传送到数据中 $result = mysql_query($sql); //处理数据 echo "<table border=1 cellspacing=0 width=15%>"; echo "<tr><td>ID</td><td>名字</td><td>性别</td></tr>"; while($row = mysql_fetch_assoc($result)){ echo "<tr>"; echo "<td>{$row['id']}</td>"; echo "<td>{$row['name']}</td>"; echo "<td>{$row['sex']}</td>"; echo "<tr>"; }$page_banner="<a href='".$_SERVER['PHP_SELF']."?p=".($page-1)."'>上一页</a>"; $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($page+1)."'>下一页</a>"; echo $page_banner; ?>
Create function $page_banner
$_SERVER['PHP_SELF'] is often used during development and is generally used to reference the current web page address
$page_banner="<a href='".$_SERVER['PHP_SELF']."?p=".($page-1)."'>上一页</a>"; $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($page+1)."'>下一页</a>";
$page The current page -1 is the previous page
$page The current page +1 is the next page
The difficulty of this chapter
$_SERVER Get the current page URL
Next Section