<?php //传入分页 $page = $_POST['p']; //链接数据库 $host= "localhost"; $username="root"; $password=""; $db ="bbs"; //连接数据库 $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 mes LIMIT " .($page-1)*10 .",10"; //把sql语句传递数据库 $result = mysql_query($sql); //处理我们的数据 echo "<table border=1 cellspacing=0>"; echo "<tr><td>ID</td><td>USERNAME</td></tr>"; while($row = mysql_fetch_assoc($result)){ echo "<tr>"; echo "<td>{$row['id']}</td>"; echo "<td>{$row['user']}</td>"; echo "</tr>"; echo $row['id'].'-'.$row['user']."<br>"; } echo "</table>"; ?>
出错详情是
Notice: Undefined index: p in D:\XAMPP\htdocs\PHP\page.php on line 3
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in D:\XAMPP\htdocs\PHP\page.php on line 32
LUCK星001