如何在mysql php中分页

I have a script of pagination. When I run, it show the following error:

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

Here's my script:

<?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> ';
}
}
?>

At last i found my problem. It was for $X. The correct is:

echo  ($number == $page) ? '<strong> <a href="?page='.$number.'">'.$number.'</a></strong> ' : '<a href="?page='.$number.'">'.$number.'</a> ';

First you need to debug your script and use mysql_error(). Then fix your sql errors.

It will then become obvious that example count 'id' should be count(id)

The error mysql_* expects parameter 1 to be resource, boolean given is usually an indicator that your MySQL query contains some error.

One obvious syntax error is that in your queries, you should use a grave accent instead of a quote around column and table names. (Grave accents are these: `. Found at the top left of most English keyboards)