确定最后一页以及每页最大行数,下一页

时间:2013-07-27 11:11:06

标签: php

我有这段代码将用户重定向到他们的帖子。

我的帖子脚本中的片段,这将获得最后一页:

// Determine on what page the post will be located
$perPage = 10;

$stmt = $db->query("SELECT * FROM posts WHERE topic_id = $id");
$row_count = $stmt->rowCount();
$page_to_redirect_to = ceil($row_count / $perPage);

// further down...

// redirect the user to their newly posted reply
header ("Location: thread.php?id=$id&page=$page_to_redirect_to#post$postid");

现在这很好用。直到最后一页有10个帖子。

如果theres,例如,一个主题有75页,而在最后一页(75),它目前是10个帖子。现在,如果有人添加了新帖子,我希望将它们重定向到第76页。

我该怎么做?老实说,我不知道。

1 个答案:

答案 0 :(得分:0)

在代码中添加以下附加语句。

if(($row_count % $perPage)==0)
{
  $page_to_redirect_to++;
}