Skip to content
Advertisement

DataTables warning: Non-table node initialisation (TBODY). PHP

I’m trying to use DataTables second time in other PHP Page but I’m stock in this error,

DataTables warning: Non-table node initialisation (TBODY).

What did i do wrong? i tried this code with my first PHP Page and its working fine.

Here is my Code for Table

<table class="table table-striped table-hover ">
          <div class="row">
              <div class="col-lg-12">
                  <div class="page-header">
                      <h1 id="tables">Admin's Accounts</h1>
                  </div>
                      <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#modal"><i class="zmdi zmdi-plus-circle zmdi-hc-2x"></i></button>
                      <table class="table table-striped table-hover ">
                          <thead>
                              <tr>
                                  <th>#</th>
                                  <th>Name</th>
                                  <th>Contact</th>
                                  <th>Email Address</th>
                                  <th>Position</th>
                                  <th>Option</th>
                              </tr>
                          </thead>
                          <tbody id="admin">
                                  <?php
                            //set up mysql connection
                            mysql_connect("localhost", "root", "") or die(mysql_error());
                            //select database
                            mysql_select_db("brm_dbs") or die(mysql_error());
                                    //select all records form tblmember table
                                    $query = 'SELECT uid,name,contact,email,position FROM admin ORDER BY created_at DESC';
                                    //execute the query using mysql_query
                                    $result = mysql_query($query);
                                   //then using while loop, it will display all the records inside the table
                                    while ($row = mysql_fetch_array($result)) {
                                        echo ' <tr> ';
                                        echo ' <td> ';
                                        echo $row['uid'];
                                        echo ' <td> ';
                                        echo $row['name'];
                                        echo ' <td> ';
                                        echo $row['contact'];
                                        echo ' <td> ';
                                        echo $row['email'];
                                        echo ' <td> ';
                                        echo $row['position'];
                                        echo '<td>';
                                        echo '<button type="button" class="btn btn-link" data-toggle="modal" data-target="#myModal'.$row['uid'].'"><i class="zmdi zmdi-plus-circle zmdi-hc-2x"></i></button>';
                                    }
                              ?>
                          </tbody>
                  </table> 
              </div>
          </div>
          </table> 

And I’m using this for JQUERY

<script src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.9/js/dataTables.bootstrap.min.js"></script>
    <script>
         $(document).ready(function() {
             $('#admin').DataTable( {
                 "lengthMenu": [[5, 10, 25, -1], [5, 10, 25, "All"]]
             });
         } );
    </script>

Advertisement

Answer

I edit my Code for Table, I have Syntax Error 6TH but 7TD and only removed the last TD in echo and its working fine now.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement