使用PDO自动加载分页


autoload pagination using PDO

我正在尝试使用jquery创建一个自动加载分页。

为什么不起作用
我在分页方面有一些问题。我直接在数据库控制台上执行了查询,并且运行良好。

if(isset($_GET['id']))
{
$get=$_GET['id'];   
}
else
{
$get=1; 
}
$limit=6;
$page = (int) (!isset($_GET['p'])) ? 1 : $_GET['p'];
$sqlw = $connect->prepare("SELECT * FROM `product` WHERE `subid`=:subid");
$sqlw->bindParam(':subid',$get, PDO::PARAM_INT);
$sqlw->execute();
$num_rows=$sqlw->rowCount();
$start = ($page * $limit) - $limit;
if($num_rows>($page * $limit))
{
 $next = ++$page;
}
$sa = $connect->prepare("SELECT * FROM `product` WHERE `subid`=:subid LIMIT :start,:limit");
$sa->bindParam(':subid',$get, PDO::PARAM_INT);
$sa->bindParam(':start',$start, PDO::PARAM_INT);
$sa->bindParam(':limit',$limit, PDO::PARAM_INT);
$sa->execute();
while($f = $sa->fetch(PDO::FETCH_OBJ))
{
$f->id;
$f->name;
$f->detail;
}
}
$s=$sa->rowCount();
if ($s < 1) 
{
header('HTTP/1.0 404 Not Found');
echo '<script>document.location.href="404.php";</script>';
exit();
}
<?php if(isset($next)): ?>
 <div class="nav">
  <a href="category.php?p=<?php echo $next; ?>&id=<?php echo $get; ?>">»</a>
 </div>
<?php endif?>

看起来在while循环末尾的代码中有一个额外的"}":

}
$s=$sa->rowCount();

应该是:

$s=$sa->rowCount();