PHP DataTables Error

0

Hi everyone, I try to use dataTables with Php, from Mysql data, but I get the following error:

  

DataTables warning table id = example1-Request unknown parameter '0' for row 0

This is my code

          <table id="example1" class="table table-bordered table-striped">
            <thead>
            <tr>
              <th>Clave</th>
              <th>Nombre</th>
              <th>Apellido Paterno</th>
              <th>Apellido Materno</th>
            </tr>
            </thead>
            <tbody>
            <tr>
              <?php
              $query="select * from directores";
              $sql=mysqli_query($cn,$query);
              $total=mysqli_num_rows($sql);
                while($row=mysqli_fetch_array($sql))
                {
                  ?>
                  <tr>
                  <td><?php echo $row['clave'];?></td>
                  <td><?php echo $row['nombre'];?></td>
                  <td><?php echo $row['apepat'];?></td>
                  <td><?php echo $row['apemat'];?></td>
                </tr>
                  <?php
                }
              ?>
            </tr>
            </tbody>
          </table>


   <script src="../../plugins/datatables/jquery.dataTables.min.js"></script>
   <script src="../../plugins/datatables/dataTables.bootstrap.min.js"></script>

  <script>
   $(function () {
   $("#example1").DataTable({
   "language": {
                "sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_ registros",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningún dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "Buscar:",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Último",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                },
                "oAria": {
                    "sSortAscending":  ": Activar para ordenar la columna de manera ascendente",
                    "sSortDescending": ": Activar para ordenar la columna de manera descendente"
                }
            }

      });
      });
   </script>

It shows me the data correctly , but when doing the load of the page it shows me the error described above.

    
asked by Rastalovely 03.03.2017 в 18:38
source

1 answer

4

The error occurs because you declare a tr element and then you generate many tr within it.

Where it says:

<tbody>
  <tr>
    <?php
      $query="select * from directores";
      $sql=mysqli_query($cn,$query);
      $total=mysqli_num_rows($sql);
      while($row=mysqli_fetch_array($sql))
        {
    ?>
       <tr>
              <td><?php echo $row['clave'];?></td>
              <td><?php echo $row['nombre'];?></td>
              <td><?php echo $row['apepat'];?></td>
              <td><?php echo $row['apemat'];?></td>
       </tr>
    <?php
            }
    ?>
    </tr>
</tbody>

I should say:

<tbody>
    <?php
      $query="select * from directores";
      $sql=mysqli_query($cn,$query);
      $total=mysqli_num_rows($sql);
      while($row=mysqli_fetch_array($sql))
        {
    ?>
       <tr>
              <td><?php echo $row['clave'];?></td>
              <td><?php echo $row['nombre'];?></td>
              <td><?php echo $row['apepat'];?></td>
              <td><?php echo $row['apemat'];?></td>
       </tr>
    <?php
            }
    ?>
</tbody>
    
answered by 03.03.2017 / 18:46
source