<?php
//傳入分頁(yè)
$page?=?$_POST['p'];
//鏈接數(shù)據(jù)庫(kù)
$host=?"localhost";
$username="root";
$password="";
$db?="bbs";
//連接數(shù)據(jù)庫(kù)
$conn=?mysql_connect($host,$username,$password);
if?(!$conn){
echo?"數(shù)據(jù)庫(kù)連接失敗";
exit;
}
//選擇需要操作的數(shù)據(jù)庫(kù)
mysql_select_db($db);
//設(shè)置數(shù)據(jù)庫(kù)的編碼格式
mysql_query("SET?NAMES?UTF8");
//編寫sql獲取分頁(yè)數(shù)據(jù)select?*from?表名?limit?起始位置,顯示條數(shù)
$sql="SELECT?*?FROM?mes?LIMIT?"?.($page-1)*10?.",10";
//把sql語(yǔ)句傳遞數(shù)據(jù)庫(kù)
$result?=?mysql_query($sql);
//處理我們的數(shù)據(jù)
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>";
?>出錯(cuò)詳情是Notice: Undefined index: p in?D:\XAMPP\htdocs\PHP\page.php?on line?3Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in?D:\XAMPP\htdocs\PHP\page.php?on line?32
2 回答
已采納

LUCK星001
TA貢獻(xiàn)19條經(jīng)驗(yàn) 獲得超21個(gè)贊
判斷下數(shù)據(jù)庫(kù)是否連接成功沒(méi)
$conn = mysql_connect($host,$user,$pwd);
if(!mysql_select_db($database)){
echo "連接數(shù)據(jù)庫(kù)失??!";
}
mysql_query('set names utf8',$conn);
添加回答
舉報(bào)
0/150
提交
取消