Skip to content
Advertisement

Pagination does not display the last two data from the database

This is where I set the number of pages and starting point:

    <?php
        $connection = mysqli_connect("localhost", "root");
        $db = mysqli_select_db($connection, 'db_hotelreservation');

        if(isset($_GET['page'])){
            $page = $_GET['page'];
        }
        else {
            $page = 1;
        }

        $number_per_page = 02;
        $start_from = ($page-1)*02;
        echo "$start_from";
        $query = "SELECT * FROM tbl_reservation WHERE room_status = 'Pending' OR room_status = 'Booked' LIMIT $start_from,$number_per_page";
        $query_run = mysqli_query($connection, $query);
        $resultCheck = mysqli_num_rows($query_run);
    ?>  

This is where the looping and the buttons:

    <?php 
        $query_result = "SELECT * FROM tbl_reservation WHERE room_status = 'Pending' OR room_status = 'Booked'";
        $result_query = mysqli_query($connection,$query_result);
        $total_records = mysqli_num_rows($result_query);
        echo "Total Records: $total_records <br>";
        $total_page = ceil($total_records/$number_per_page);
        echo "Total Pages: $total_page <br>";

        for($i=1;$i<$total_page;$i++){
            echo "<a href='SuperAdminReserveManage.php?page=".$i."' class='btn btn-primary'>$i</a>";
        }
    ?>

Total Records: 8

Total Pages: 4

But then it only prints 3 buttons, kinda confused where did I go wrong.

Advertisement

Answer

my guess is you’re starting from 1 instead of 0 or use

for($i=1;$i<=$total_page;$i++){
....

instead

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement