简体   繁体   English

PHP-分页最后一页?

[英]PHP - Pagination Last Page?

I have a PHP pagination that is used when there are more than the desired amount per page on a forum thread. 我有一个PHP分页,当论坛线程上每页的数量超过所需数量时,将使用该分页。 (15) It only lets you go to the previous and next page though. (15)虽然它只允许您转到上一页和下一页。 I need to find a way to make a last page link. 我需要找到一种建立最后一页链接的方法。 Here's my code: 这是我的代码:

    $resulte = mysqli_query($conexion, "SELECT * FROM forumcomments WHERE forum='$id'");
    $getnumbers = mysqli_num_rows($resulte);
    $howmuchpost = $page * 15;
    $pageplus = $page + 1;
    $pageminus = $page - 1;
    $howmuchpostminus = $howmuchpost - 15;
    $postsleft = $getnumbers - $howmuchpostminus;
    if ($postsleft >= 15) {$nextpage = 'true';}
    if ($howmuchpostminus >= 15 && $page != 1) {$previouspage = 'true';}
    $posts_sql = "SELECT * FROM forumcomments WHERE forum = $id LIMIT ".$howmuchpostminus.", 15";
    $posts_result = mysqli_query($conexion, $posts_sql);

    //Display posts
    $result2 = mysqli_query($conexion, "SELECT * FROM forumcomments WHERE forum='$id' ORDER BY id LIMIT $howmuchpostminus, $howmuchpost") or die(mysqli_error($conexion));
    $num = mysqli_num_rows($result2); 
    if(!$posts_result)
    {
    echo '<tr><td>The posts could not be displayed, please try again later.</tr></td></table>';
    }else{
    while($rows = mysqli_fetch_assoc($posts_result)){
    // Now you obviously have the looping data here, removed because I don't think  this is really needed.
    }
    }

If anyone could help, I would appreciate it. 如果有人可以提供帮助,我将不胜感激。 Thanks. 谢谢。

$lastPage = ceil($getnumbers / 15);

Say you have 115 comments. 假设您有115条评论。 115 / 15 = 7.667. 115/15 = 7.667。 So you'll have 7 pages, and a bit left. 因此,您将有7页,还有一点。 By using ceil() , you round it to above, so 8. The last page would indeed be 8. 7 pages full of 15 comments, with the last page containing (115 - (7 * 15) =) 10 comments. 通过使用ceil() ,将其四舍五入为8。最后一页的确是8。7个页面充满了15条注释,最后一页包含(115-(7 * 15)=)10条注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM