我想在PHP中进行分页

时间:2016-03-28 15:01:06

标签: php pagination

我想在我的类别页面中进行分页。我正在接受这个错误

  

未定义的变量:第39行"的C:\ wamp64 \ www \ cms \ category.php中的post_category_id。

<?php
if(isset($_GET['category'])){
    $post_category_id = $_GET['category'];
}

$per_page= 2;
if(isset($_GET['categorypage'])){
    $page = $_GET['categorypage'];
}else{
    $page = "";
}

if($page == "" || $page == 1){
    $page_1 = 0;
}else{
    $page_1 = ($page * $per_page) - $per_page;
}

$post_query_count = "SELECT * FROM posts WHERE post_category_id = $post_category_id ";
$find_count = mysqli_query($connection, $post_query_count);
$count = mysqli_num_rows($find_count);
$count = ceil($count / $per_page);

$query = "SELECT * FROM posts WHERE post_category_id = $post_category_id ORDER BY post_date DESC LIMIT $page_1, $per_page ";
$select_all_posts_query = mysqli_query($connection, $query);
$num_rows = mysqli_num_rows($select_all_posts_query);

if($num_rows <= 0){
    echo "<h1 class='text-center'>THERE IS NO POST ABOUT THIS CATEGORY!</h1>";
    echo "<img style='margin-left:225px;' width='300' class='img-responsive' src='images/200.gif'/>";
}else{
    while($row = mysqli_fetch_assoc($select_all_posts_query)){
        $post_id = $row['post_id'];
        $post_title = $row['post_title'];
        $post_author = $row['post_author'];
        $post_date = $row['post_date'];
        $post_image = $row['post_image'];
        $post_content = strip_tags(substr($row['post_content'], 0, 0));           
        ?>
        <ul style="style="margin-left: auto; margin-right: auto; width: 50em; class="pager">
        <?php
        for($i = 1; $i <= $count; $i++){
            if($i == $page){
                echo "<li><a class= 'active_link' href= 'category.php?categorypage= {$i}'>{$i}</a></li>";
            }else{
                echo "<li><a href= 'category.php?categorypage= {$i}'>{$i}</a></li>";
            }
        }
        ?>    
        </ul>
    }
}

我想在用户选择类别的类别页面中进行分页。我可能会有更多关于所选类别的帖子,因此我想分页。 谢谢大家,对不起我的英语不好。

0 个答案:

没有答案