我有一个分页脚本。当我运行时,它显示以下错误:
Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\folder\index.php on line 6
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\folder\index.php on line 12
这是我的脚本:
<?php
include 'db.inc.php';
$per_page = 2;
$pages_query = mysql_query("SELECT COUNT 'id' FROM 'names'");
$pages = ceil(mysql_result($pages_query,0) /$per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$query = mysql_query("SELECT 'name' FROM 'names' LIMIT $start, $per_page");
while ($query_row = mysql_fetch_assoc($query)) {
echo '<p>', $query_row['name'],'</p>';
}
if($pages >=1 && $page <= $pages){
for ($x=1; $x<=$pages; $x++){
echo ($x == $page) ? '<strong> <a href="?page='.$X.'">'.$x.'</a></strong> ' : '<a href="?page='.$X.'">'.$x.'</a> ';
}
}
?>
最后我发现了我的问题。这是 X 美元。正确的是:
echo ($number == $page) ? '<strong> <a href="?page='.$number.'">'.$number.'</a></strong> ' : '<a href="?page='.$number.'">'.$number.'</a> ';