如何在php中对数据库表进行分页

如何在php中对数据库表进行分页,php,database,pagination,Php,Database,Pagination,我最近在学习php。我从数据库中获取该表,但在对该表进行分页时遇到问题。 我不知道如何对数据库表进行分页,我如何才能做到这一点 这是我的密码 <?php // If user not logged in then show login message if (!isset($_SESSION['userid'])) { ?><div class="message">

我最近在学习php。我从数据库中获取该表,但在对该表进行分页时遇到问题。
我不知道如何对数据库表进行分页,我如何才能做到这一点

这是我的密码

        <?php

            // If user not logged in then show login message
            if (!isset($_SESSION['userid'])) {

                ?><div class="message">
                    To access this page, you must be logged.<br />
                    <a href="connexion.php">Log in</a>
                </div><?php
            }
            else{

                //Video count values of the database
                if(isset($_REQUEST['date1']) && isset($_REQUEST['date2'])){
                    $dnn = mysqli_query($conn, 'select video_date,video_count from video_master where  rec_id="'.$_SESSION['userid'].'" and video_date >= "' . $_REQUEST['date1'] . '" and video_date <= "' . $_REQUEST['date2'] . '"');
                }
                else{
                    $dnn = mysqli_query($conn, 'select video_date,video_count from video_master where  rec_id="'.$_SESSION['userid'].'"');
                }


                if(mysqli_num_rows($dnn)>0)
                {



                    ?><table>
    <thead>
                        <tr>
                            <th>Date</th>
                            <th>Video Count</th>
                        </tr></thead><?php

                        while($rowData = mysqli_fetch_array($dnn)){
                            //$video_date = date("Y-m-d","d-m-Y",$rowData['video_date']);
                            $video_date = $rowData['video_date'];
                            $video_count = $rowData['video_count'];

                            ?><tbody><tr>
                                <td><?php print($video_date); ?></td>
                                <td><?php print($video_count); ?></td>
                            </tr></tbody><?php

                        }
                    ?></table><?php
                }   

                ?>
            <?php

            }

    ?>

要访问此页面,您必须登录。
我尝试的代码,但在这段代码中,我只得到我表下的数字。单击数字时,值不是GET CHANGE

<?php

                $per_page=5;
                if (isset($_GET["page"])) {

        $page = $_GET["page"];

        }

        else {

        $page=1;

        }
        // Page will start from 0 and Multiple by Per Page
        $start_from = ($page-1) * $per_page;

        //Selecting the data from table but with limit
        $query = "SELECT * FROM video_master LIMIT $start_from, $per_page";
        $result = mysqli_query ($conn, $query);

                // If user not logged in then show login message
                if (!isset($_SESSION['userid'])) {

                    ?><div class="message">
                        To access this page, you must be logged.<br />
                        <a href="connexion.php">Log in</a>
                    </div><?php
                }
                else{

                    //Video count values of the database
                    if(isset($_REQUEST['date1']) && isset($_REQUEST['date2'])){
                        $dnn = mysqli_query($conn, 'select video_date,video_count from video_master where  rec_id="'.$_SESSION['userid'].'" and video_date >= "' . $_REQUEST['date1'] . '" and video_date <= "' . $_REQUEST['date2'] . '"');
                    }
                    else{
                        $dnn = mysqli_query($conn, 'select video_date,video_count from video_master where  rec_id="'.$_SESSION['userid'].'"');
                    }


                    if(mysqli_num_rows($dnn)>0)
                    {



                        ?><table>
        <thead>
                            <tr>
                                <th>Date</th>
                                <th>Video Count</th>
                            </tr></thead><?php

                            while($rowData = mysqli_fetch_array($dnn)){
                                //$video_date = date("Y-m-d","d-m-Y",$rowData['video_date']);
                                $video_date = $rowData['video_date'];
                                $video_count = $rowData['video_count'];

                                ?><tbody><tr>
                                    <td><?php print($video_date); ?></td>
                                    <td><?php print($video_count); ?></td>
                                </tr></tbody><?php

                            }
                        ?></table><?php
                        //Now select all from table
        $query = "select * from video_master";
        $result = mysqli_query($conn, $query);

        // Count the total records
        $total_records = mysqli_num_rows($result);

        //Using ceil function to divide the total records on per page
        $total_pages = ceil($total_records / $per_page);

        //Going to first page
        echo "<center><a href='reports.php?page=1'>".'First Page'."</a> ";
        for ($i=1; $i<=$total_pages; $i++) {

        echo "<a href='reports.php?page=".$i."''>".$i."</a>";
        };
        // Going to last page
        echo "<a href='reports.php?page=$total_pages'>".'Last Page'."</a></center> ";


                    }   

                    ?>
                <?php

                }

        ?>

要访问此页面,您必须登录。

您的分页代码在哪里等等,先生,我会编辑我的问题,我会尝试@MayankVadiyatry搜索它的easySIR我编辑我的问题我得到了其中的页码,但表值没有改变使用偏移量和限制在查询中这是你的分页代码等等先生,我会编辑我的问题,我尝试@MayankVadiyatry搜索它的easySIR我编辑我的问题我得到了其中的页码,但表值没有改变使用偏移量和限制在查询中