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

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

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条)

报告相同问题?