表中没有可用数据,但显示数据库中的数据

时间:2016-08-02 09:33:24

标签: javascript php jquery datatables

数据表显示数据库的内容但仍显示错误消息:表中没有可用数据。 我该如何解决这个问题,只显示没有错误信息的数据

<table name= "displaycase" id="example1" class="table table-bordered table-striped" method = "post">
  <thead>
    <tr>
      <th>Case Title</th>
      <th>Court</th>
      <th>Dockent Number</th>
      <th>Nature</th>
      <th>Actions Taken</th>
      <th>Status</th>
      <th>Due Date </th>
    </tr>
  </thead>
  <tbody>
  <tbody class = "searchable">
    <?php
    if (mysql_num_rows($result) > 0) {
      // output data of each row
      while ($row = mysql_fetch_assoc($result)) {
        echo
        "</td><td>" . $row["CaseTitle"] .
        "</td><td>" . $row["Court"] .
        "</td><td>" . $row["docketNum"] .
        "</td><td>" . $row["nature"] .
        "</td><td>" . $row["actionsTaken"] .
        "</td> <td>" . $row["status"] .
        "</td> <td>" . $row["dueDate"] .
        "</td></tr>";
      }
    } else {
    }
    ?>
  </tbody>

-

<script>
        $( document ).ready(function() {
        $("#example1").DataTable({
            "paging": false,
            "ordering": true,
            "info": false,
            "language": {
                "emptyTable": "No Data"
            }
          })
    });</script>

enter image description here

2 个答案:

答案 0 :(得分:2)

  1. method = "post"代码中删除<table>
  2. 为什么<tbody>内有两个<table>标记。删除一个。
  3. 为什么</td>在尚未打开时关闭。
  4. 没有<tr>已开启。
  5. 更新代码:

    <table name= "displaycase" id="example1" class="table table-bordered table-striped">
      <thead>
        <tr>
          <th>Case Title</th>
          <th>Court</th>
          <th>Dockent Number</th>
          <th>Nature</th>
          <th>Actions Taken</th>
          <th>Status</th>
          <th>Due Date </th>
        </tr>
      </thead>
    
      <tbody class = "searchable">
        <?php
        if (mysql_num_rows($result) > 0) {
          while ($row = mysql_fetch_assoc($result)) {
            echo
            "<tr>".
              "<td>" . $row["CaseTitle"] ."</td>".
              "<td>" . $row["Court"] ."</td>".
              "<td>" . $row["docketNum"] ."</td>".
              "<td>" . $row["nature"] ."</td>".
              "<td>" . $row["actionsTaken"] ."</td>".
              "<td>" . $row["status"] ."</td>".
              "<td>" . $row["dueDate"] ."</td>".
            "</tr>";
          }
        } else {
    
        }
        ?>
      </tbody>
    </table>
    

    [注意The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

答案 1 :(得分:0)

那是因为你错过了tr,而是在回声中回显</td>

while($row = mysql_fetch_assoc($result)) {
     echo 
     "<tr><td>".$row["CaseTitle"].
     "</td><td>".$row["Court"].
     "</td><td>".$row["docketNum"].
     "</td><td>".$row["nature"].
     "</td><td>".$row["actionsTaken"].
     "</td> <td>".$row["status"].
     "</td> <td>".$row["dueDate"].
     "</td></tr>";
}