使用php或js进行分页

时间:2019-03-18 21:02:53

标签: javascript php jquery

我有这个php代码,该代码使用userid从数据库中获取图像,然后以列表形式显示所有图像。我试图分页图像,每页限制5个项目。但代码仅显示第一页,而没有指向其他页面的链接。这是我的PHP代码

<?php
    include 'connect.php';


        $Category = " ";
        $query = "SELECT Img_dir, Caption, Category FROM images WHERE Category = '". $_REQUEST['Category'] ."' AND user_id = '". $_SESSION['user_id'] ."' LIMIT 0,5";


        $result = mysqli_query($conn,$query);


        while ($row=mysqli_fetch_array($result)){
            $image = $row["Img_dir"];
            $Caption= $row["Caption"];
            $Category = $row["Category"];
                echo "<dl>";

                echo "<dd>$Category &nbsp&nbsp <img src='base64_encode($image)' />&nbsp&nbsp $Caption<dd>";

                echo "</dl>";
                }
        //number of total pages available
        $results_per_page = 10;

        $number_of_results = mysqli_num_rows($result);

        echo $number_of_pages = ceil($number_of_results / $results_per_page);
        echo "<br>"; echo "<br>";
        for($r=1;$r<=$number_of_pages;$r++)
        {
            ?><a href="dashboard.php?page=<?php echo $r;?>" style="text-decoration:none"><?php echo $r." "; ?></a><?php 
        }

?>

0 个答案:

没有答案