Home » Php » Why is DataTable only loading 5 out of 22 records in PHP/MySql?

Why is DataTable only loading 5 out of 22 records in PHP/MySql?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am certain that I am missing something small here but it had me going for 2 days now.

I am doing a SELECT STATEMENT with criteria, populate a DataTable and view records. My problem is that only 5 records is loaded whilst there are 22 records available. I did echo out each line and 22 is returned, not sure where my problem is and I will appreciate any help please.

I have a suspicion that the problem might be in the next line of code where the User_Role is to be returned, no errors though so I am not sure –

$resultUser = $db->get_row_by_field($User_Role_Data,$part_result->userID,'ID');

Code for Datatable (I played around with all options here, not helping) –

<script id="rendered-js">
$(document).ready(function () {
    $("table").DataTable({
        dom: "<'dt-head clearfix'lrf>t<'dt-foot clearfix'ip>",
        bServerSide: false,
        deferRender: false,
        pageLength: 3,
        autoWidth: false,
        fixedHeader: true,
        responsive: true,
        language: {
            search: "_INPUT_",
            searchPlaceholder: "Search Item",
            lengthMenu: "<select>" +
                '<option value="10">10</option>' +
                '<option value="25">25</option>' +
                '<option value="50">50</option>' +
                '<option value="100">100</option>' +
                '<option value="-1">All</option>' +
                "</select> View Rows Per Page",
            oPaginate: {
                sNext: "<i class='fa fa-mail-forward'></i>",
                sPrevious: "<i class='fa fa-mail-reply'></i>"
            }
        }
    });
});

This is the PHP code that returns the records, as above, return is fine, displaying is only 5 –enter image description here

<tbody>
<?php
$total  =   0;
$dealer_id  =   $user->dealerID;

$part_results =     $db->get_results("SELECT * FROM wp_ims_part_booked WHERE dealerid='".$dealer_id."' AND isInvoiced='0' AND isCancelled='0' ORDER BY date_booked ASC");

if(count($part_results)>0){
    foreach($part_results as $part_result){
        $result         =   $db->get_row_by_field($part_result->partTable,$part_result->partID,'ID');
        $bookingID  = $db->get_row_by_field($part_result->partTable,$part_result->bookingID,'ID');

    switch($part_result->user_role) {
        case "Franchise Dealer":
            $User_Role_Data = "wp_ims_user_dealer";
            break;

        case "OEM Retailer":
            $User_Role_Data = "wp_ims_user_oem";
            break;

        case "Non-OEM Part Retailer":
            $User_Role_Data = "wp_ims_user_non_oem";
            break;

        case "Insurance Company":
            $User_Role_Data = "wp_ims_user_insurance";
            break;

        case "Panel/Body Repair Shop":
            $User_Role_Data = "wp_ims_user_panel";
            break;

        case "Private Individual":
            $User_Role_Data = "wp_ims_user_public";
            break;
        case "Non-Franchise Workshop":
            $User_Role_Data = "wp_ims_user_non_franchise_wshop";
    }
    $resultUser         =   $db->get_row_by_field($User_Role_Data,$part_result->userID,'ID');
?>
<tr>
    <td style="color: #0d9b84; text-align: center; width: 30px;">
        <?php echo "#".$part_result->ID?>
    </td>
    <td style="color: #0d9b84; text-align: center; width: 80px;">
        <?php echo $result->partnumber;?>
    </td>
    <td style="color: #0d9b84; text-align: center; width: 200px;">
        <?php echo $result->partdescription;?>
    </td>
    <td style="color: #0d9b84; text-align: center; width: 70px;">
        <?php echo "R ".number_format(($part_result->value_booked_for), 2);?>
    </td>
    <td style="color: #0d9b84; text-align: center; width: 220px;">
        <?php echo "Client: ".$resultUser->name." ".$resultUser->surname;
              echo "<br>";
              echo "Contact No: ".$resultUser->contactnumber;
              echo "<br>";
              echo "City: ".$resultUser->usercity;
              echo "<br>";
              echo "Province: ".$resultUser->userprovince;
        ?>
    </td>
    <td style="color: #0d9b84; text-align: center; width: 100px;">
        <?PHP
            echo $part_result->date_booked;
        ?>
    </td>
    <td style="color: #0d9b84; text-align: center; width: 250px;">
        <input type="hidden" name="ID" value="<?php echo $part_result->ID;?>" />
        <input type="hidden" name="bookingID" value="<?php echo $bookingID;?>" />
        <textarea rows="2" cols="30" class="contact-form-text" style="width: 100%; margin-top: 3px;" placeholder="ENTER YOUR NOTE (Required On Cancel)" required></textarea>
        <a href="ims_cancel_client_purchase.php?ID=<?php echo $part_result->ID;?>&bookingID=<?php echo $bookingID;?>" class="btn btn-warning btn-block" style="color: #edf61a;">
            Cancel Purchase X
            <i class="fa fa-angle-right"></i>
        </a>
        <a href="ims_invoice_to_client.php?ID=<?php echo $part_result->ID;?>&bookingID=<?php echo $bookingID;?>" class="btn btn-success btn-block" style="color: #4cff00;">
            Invoice To Client
            <i class="fa fa-angle-right"></i>
        </a>
        <br />
    </td>
</tr>
<?php
    }
?>
<?PHP } else { ?>
<tr>
    <th style="width:900px; text-align: center; font-weight: 600; font-size: 16px; color: #ff6a00;" class="min-tablet-l">
        No Outstanding Orders or Bookings found for your Dealership.
    </th>
</tr>
<?php } ?

Further notice (see image), the last record does not show the far right column buttons or textarea box, not sure why.enter image description here

How to&Answers: