我试图让分页在我的页面上工作,但遇到错误:
mysql_result() expects parameter 1 to be resource, object given in
我想我需要使用mysqli
命令,但似乎无法弄明白。这是我的代码
$connect = mysqli_connect('localhost', 'root', 'password', 'vdb');
$per_page = 6;
$pages_query = mysqli_query($connect, "SELECT COUNT(id) FROM customers");
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$query = mysqli_query($connect, "SELECT cid, fname, lname,address, score FROM customers");
while ($query_row = mysqli_fetch_assoc($query)) {
$array[] = $query_row['fname'] . '<br />';
}
if($pages >= 1)
{
for($x=1; $x <= $pages; $x++)
{
echo '<a href="?page='.$x.'">' .$x.'</a>';
}
}
提前致谢!
答案 0 :(得分:1)
你在mysql
和mysqli
$pages_query = mysqli_query($connect, "SELECT COUNT(id) FROM customers"); // MySQLi
$pages = ceil(mysql_result($pages_query, 0) / $per_page); // MySQL
答案 1 :(得分:0)
应该有mysqli_result
而不是mysql_result
。切勿混淆它们,只使用mysqli_*
个功能。
// line 3 of code above
$pages = ceil(mysqli_result($pages_query, 0) / $per_page);
^^