Php 确定最后一页,如果每页最多行,则确定下一页
我用这段代码将用户重定向到他们的帖子 我的帖子脚本中的代码片段,这将获得最后一页:Php 确定最后一页,如果每页最多行,则确定下一页,php,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
// 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++;
}
似乎不起作用,即使页面上只有3篇帖子,它仍然会增加。如果有10篇文章,我只想把页码增加1