首页 > 解决方案 > 为什么 DataTable 只加载 PHP/MySql 中 22 条记录中的 5 条?

问题描述

我确信我在这里遗漏了一些小东西,但它现在让我走了 2 天。

我正在使用标准执行 SELECT STATEMENT,填充 DataTable 并查看记录。我的问题是只加载了 5 条记录,而有 22 条记录可用。我确实回显了每一行并返回了 22,不确定我的问题出在哪里,我将不胜感激。

我怀疑问题可能出在要返回 User_Role 的下一行代码中,但没有错误,所以我不确定 -

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

数据表的代码(我在这里玩了所有选项,没有帮助) -

<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>"
            }
        }
    });
});

这是返回记录的PHP代码,如上,返回没问题,显示只有5 -在此处输入图像描述

<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 } ?

进一步通知(见图),最后一条记录没有显示最右边的列按钮或文本区域框,不知道为什么。在此处输入图像描述

标签: phpmysqldatatable

解决方案


推荐阅读