在for循环语句中添加分页链接的正确方法是什么

时间:2019-01-31 15:32:20

标签: php mysqli

我有一个Web应用程序,显示几个音频内容,每个类别在页面上限制为6个项目,用户必须单击分页按钮以查看接下来的6个项目。我的页面是使用switch语句包含的,所以我不知道要在我的for循环语句中链接到哪个页面。

我尝试链接到列出该项目的实际页面,但是这将我带回到switch语句中的默认页面。下面是我有for循环和分页脚本h_files.php的代码,但它包含在名为audio.php的文件中,当用户单击分页按钮而不是加载接下来的6个项目时,它将加载默认的switch语句。如果我将for循环中的链接从audio.php更改为h_files.php,则找不到提示页面。

<?php
$per_page = 6;
if(isset($_GET['page'])){
    $page = $_GET['page'];
}
else
{
    $page = "";
}

if($page == "" || $page == 1)
{
    $page_1 = 0;
}
else
{
    $page_1 = ($page * $per_page) - $per_page;
}
$post_query_count = "SELECT * FROM post WHERE 
content LIKE 'H%'";
$find_count = mysqli_query($connection, 
$post_query_count);
$count = mysqli_num_rows($find_count);
$count = ceil($count / $per_page);                      

$query = "SELECT * FROM post WHERE content LIKE 'H%' ORDER BY 
postId DESC LIMIT $page_1, $per_page";
$select = mysqli_query($connection, $query);
if (mysqli_num_rows( $find_count) == 0)
{
    echo '    <div class="col-md-4">
    No Result
    </div>';
}
else
{
    while($row = mysqli_fetch_assoc($select)){
        //$content_header = $row['header'];
        //$content_body = $row['content'];
        $image = $row['image'];
        $audio = $row['audio'];
        $category = $row['category'];
        $content = $row['content'];
        $date = $row['date'];
        //$image4 = $row['image4'];
        ?>
        <div class="col-md-4">
            <div class="post post-sm" style="background-color:#ee4266; box-shadow: 
            5px 5px 6px #666666;">
                <a class="post-img" href="blog-post.html">
                <img src="images/<?php echo $image; ?>" alt=""></a>
                <div class="post-body">
                    <div class="post-category">
                        <audio controls style = "margin-left:4px">
                        <source src="audio/<?php echo $audio; ?>" type="audio/mpeg" >
                    </audio>
                    </div>
                    <h3 class="post-title title-sm" style="padding:8px;">
                        <a href="blog-post.html"><span style="color:#FFFFFF">
                        <?php echo $content; ?></span></a>
                    </h3>
                    <ul class="post-meta">
                        <li><a href="audio/<?php echo $audio; ?>
                        "class="fa fa-download fa-1x" style="padding:8px;" download> 
                        Download</a></li>
                        <li><?php echo $date; ?></li>
                    </ul>
                </div>
            </div>
        </div>
        <?php
    }
    ?>
    <?php 
}
?>
<div class="row">
    <div class="col col-lg-4">
    </div>
    <ul class="pagination">
        <?php
        for($i = 1; $i <= $count; $i++){
            echo "<li '><a href = 'audio.php?page={$i}'> {$i} </a></li>";
        }
        ?>
    </ul>
    <div class="col col-lg-2">
    </div>
</div>

以上文件通过switch语句包含在audio.php中。问题出在哪里,在链接中。

0 个答案:

没有答案