dqqvravff05370501 2018-10-10 06:43
浏览 55
已采纳

“表中没有可用的数据”,表中甚至存在数据

Why does my table displays the error "No data available in the Table" and shows "Showing 0 of 0 entries" below. Here is the screenshot

I have no idea why does this happen. I'm using mysqli_fetch_assoc to get the data from my query.

<div class="card mb-3">
    <div class="card-header">
        <i class="fas fa-table"></i>
        Data Table
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                <thead>
                    <tr>
                        <th>Ref. No.</th>
                        <th>Date/Time</th>
                        <th>Line No.</th>
                        <th>Optr. Name</th>
                        <th>Weight</th>
                        <th>Moisture</th>
                        <th>Product ID</th>
                        <th>Item Code</th>
                    </tr>
                    <?php while ($rows = mysqli_fetch_assoc($sql)) { ?>
                        <tr>
                            <td><?php echo $rows['mb_refno']; ?></td>
                            <td><?php echo $rows['mb_weight_dt']; ?></td>
                            <td><?php echo $rows['mb_line_id']; ?></td>
                            <td><?php echo $rows['mb_opt_name']; ?></td>
                            <td><?php echo $rows['mb_weight']; ?></td>
                            <td><?php echo $rows['mb_moisture']; ?></td>
                            <td><?php echo $rows['mb_prod_id']; ?></td>
                            <td><?php echo $rows['mb_prod_code']; ?></td>
                        </tr>
                    <?php } ?> 
                </tbody>
            </table>
        </div>
    </div>
    <div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div>
</div>


<tbody>
  <?php while ($rows = mysqli_fetch_assoc($sql)) { ?>
    <tr>
      <td><?php echo $rows['mb_refno']; ?></td>
      <td><?php echo $rows['mb_weight_dt']; ?></td>
      <td><?php echo $rows['mb_line_id']; ?></td>
      <td><?php echo $rows['mb_opt_name']; ?></td>
      <td><?php echo $rows['mb_weight']; ?></td>
      <td><?php echo $rows['mb_moisture']; ?></td>
      <td><?php echo $rows['mb_prod_id']; ?></td>
      <td><?php echo $rows['mb_prod_code']; ?></td>
    </tr>
    <?php } ?>  
</tbody>
  • 写回答

2条回答 默认 最新

  • doufei5315 2018-10-10 06:59
    关注

    FYI dataTables requires a well formed table. It must contain <thead> and <tbody> tags, otherwise it throws this error. Also, check to make sure all your rows including header row have the same number of columns.

    <div class="card mb-3">
        <div class="card-header">
            <i class="fas fa-table"></i>
            Data Table
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Ref. No.</th>
                            <th>Date/Time</th>
                            <th>Line No.</th>
                            <th>Optr. Name</th>
                            <th>Weight</th>
                            <th>Moisture</th>
                            <th>Product ID</th>
                            <th>Item Code</th>
                        </tr>
                     </thead>
                     <tbody>
                        <?php while ($rows = mysqli_fetch_assoc($sql)) { ?>
                            <tr>
                                <td><?php echo $rows['mb_refno']; ?></td>
                                <td><?php echo $rows['mb_weight_dt']; ?></td>
                                <td><?php echo $rows['mb_line_id']; ?></td>
                                <td><?php echo $rows['mb_opt_name']; ?></td>
                                <td><?php echo $rows['mb_weight']; ?></td>
                                <td><?php echo $rows['mb_moisture']; ?></td>
                                <td><?php echo $rows['mb_prod_id']; ?></td>
                                <td><?php echo $rows['mb_prod_code']; ?></td>
                            </tr>
                        <?php } ?> 
                    </tbody>
                </table>
            </div>
        </div>
        <div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div>
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM