【问题标题】:autoload pagination using PDO使用 PDO 自动加载分页
【发布时间】:2016-08-01 01:34:21
【问题描述】:

我正在尝试使用 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?>

【问题讨论】:

    标签: php ajax pdo pagination


    【解决方案1】:

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

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

    应该是:

    $s=$sa->rowCount();
    

    【讨论】:

      猜你喜欢
      • 2013-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-19
      • 2012-11-16
      相关资源
      最近更新 更多