PHP分页不起作用

时间:2017-05-26 17:44:19

标签: php html css mysql mysqli

我使用以下代码从表中进行分页,我的表名为category,第二个posts和名为setting

的名称
<div id="wrap">
      <div class="container" style="margin-top:50px;">
<div class="row">
<?php
   $per_page =8;
        if (!isset($_GET['page'])) 
        {
            $page = 1;
        }
        else
        {
            $page = (int)$_GET['page'];
        }
        $start_f = ($page-1) * $per_page;
$query = mysqli_query($conn, " SELECT * FROM `posts` p INNER JOIN `users` u 
WHERE p.p_author = u.u_id AND `p_category` = '$_GET[category]' ORDER BY `p_id` DESC LIMIT $start_f , $per_page" );
while ( $post = mysqli_fetch_assoc($query)) {
# code...
?>
    <div class="col-xs-12 col-sm-6 col-md-3" style="margin-top: 20px;">
        <div class="col-item" >
            <div class="post-img-content">

                <img src="<?php echo $post['p_image']; ?>" style="width: 100%; height: 100%;" class="img-responsive" />

                <span class="post-title">
                    <b class="pull-left"><?php echo $post['p_title']?></b>

                 </span>


            </div>
            <div>

            <div class="info" >

                <div class="row ">
                    <div class="col-md-12"></div>
                    <div class="price col-md-6">

                       <h5><b><?php echo $post['p_category'];?></b></h5>

                    </div>
                    <div class=" hidden-sm col-md-6">
                        <h5 style="text-align: right;"><a href="admin-cp/profile.php?user=<?php echo $post['u_id']; ?>"><b ><?php echo 
 $post['u_name'];?></b></a></h5>

                    </div>
                    <div class=" hidden-sm col-md-12">
                    <h5><b>Date : </b><?php echo $post['p_date'];?></h5>
                    </div>
                </div>
                <div class="separator clear-left">
                    <p style="text-align: left;">
                        <i class="fa fa-eye"></i><a href="p_details.php?id=<?php echo $post['p_id']?>" class="hidden-sm">View</a></p>

                </div>
                <div class="clearfix">
                </div>
            </div>
            </div>
        </div>
    </div>
 <?php
}
                           $page_sql = mysqli_query($conn, "SELECT * FROM 
 `posts` WHERE `p_category` = '$_GET[category]'");
                           $count_page = mysqli_num_rows($page_sql);
                           $total_page = ceil($count_page/$per_page); /// cail for make value int

                            ?>  
                            <nav class="text-center">
                            <ul class="pagination">
                            <?php 
                           for($i = 1 ; $i <= $total_page; $i++)
                           {
                            echo '<li '.($page==$i ? 'class="active"' : '').' ><a href="category.php?category='.$_GET['category'].'?page='.$i.'">'.$i.'</a></li>';
                           }

                           ?>


                    </ul>
                  </nav>
</div>

这个http://localhost/p/category.php?category=Computers工作并给我第一页,但http://localhost/p/category.php?category=Computers?page=1给我0结果 请求帮助我这对我来说非常重要

1 个答案:

答案 0 :(得分:0)

链接连接错误,use & instead of ? again

<?php
}
                           $page_sql = mysqli_query($conn, "SELECT * FROM 
 `posts` WHERE `p_category` = '$_GET[category]'");
                           $count_page = mysqli_num_rows($page_sql);
                           $total_page = ceil($count_page/$per_page); /// cail for make value int

                            ?>  
                            <nav class="text-center">
                            <ul class="pagination">
                            <?php 
                           for($i = 1 ; $i <= $total_page; $i++)
                           {
                            echo '<li '.($page==$i ? 'class="active"' : '').' ><a href="category.php?category='.$_GET['category'].'&page='.$i.'">'.$i.'</a></li>';
                           }

                           ?>