确定最后一页,如果每页最多行数,则确定下一页


Determine the last page and if max rows per page, next page

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

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

// 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个帖子。

比如说,如果一个主题有75页,而在最后一页(75页)上,目前有10条帖子。现在,如果有人添加了一个新的帖子,我希望他们被重定向到第76页。

我该怎么做?我真的不知道。

将以下附加语句添加到代码中。

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