Php 使用PDO自动加载分页

Php 使用PDO自动加载分页,php,ajax,pdo,pagination,Php,Ajax,Pdo,Pagination,我正在尝试使用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` WH

我正在尝试使用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?>
if(isset($\u GET['id']))
{
$get=$\u get['id'];
}
其他的
{
$get=1;
}
$limit=6;
$page=(int)(!isset($\u GET['p'])?1:$_GET['p'];
$sqlw=$connect->prepare(“从`product`中选择*,其中`subid`=:subid”);
$sqlw->bindParam(':subid',$get,PDO::PARAM_INT);
$sqlw->execute();
$num_rows=$sqlw->rowCount();
$start=($page*$limit)-$limit;
如果($num_rows>($page*$limit))
{
$next=+$page;
}
$sa=$connect->prepare(“从`product`中选择*,其中`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();
而($f=$sa->fetch(PDO::fetch_OBJ))
{
$f->id;
$f->name;
$f->细节;
}
}
$s=$sa->rowCount();
如果($s<1)
{
标头(“未找到HTTP/1.0 404”);
echo'document.location.href=“404.php”;
退出();
}

在while循环结束时,代码中似乎有一个额外的“}”:

}
$s=$sa->rowCount();
应该是:

$s=$sa->rowCount();