1

The data table displays the the contents of the database but still shows an error message: no data available in table. how do i fix this, just show the data without the error message

<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

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
amart
  • 23
  • 5
  • What is the `method` attribute doing inside a `table` tag?!? – arkascha Aug 02 '16 at 09:36
  • if you want to display data only using datatables then you are going wrong.. you just need to add in the html/php file please check [link] https://datatables.net/examples/server_side/simple.html – Tejas Mehta Aug 02 '16 at 09:39

2 Answers2

2
  1. Remove method = "post" from <table> tag.
  2. Why Two <tbody> tag present inside <table>. Remove One.
  3. Why </td> is closed when it didn't opened yet.
  4. No <tr> opened.

UPDATE CODE:

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

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

Community
  • 1
  • 1
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
0

That's because you missed a tr and instead you echo </td> in the echo here

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>";
}
jonju
  • 2,711
  • 1
  • 13
  • 19