Improve table look with jquery

0

I have the following code in head to give a better appearance to my table but some reason does not work, the table stays like this, what can it be?

<head>

<meta charset="UTF-8">
<title>
    Tabla PHP
</title>

<script type="text/javascript" src="jquery-1.11.2.js"></script>

<link rel="stylesheet" type="text/css" 
href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">

<script type="text/javascript" 
src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"> </script>

<script type="text/javascript">

    $(document).ready( function () 
    {
    $('#tabla1').DataTable();
    } );

</script>

</head>
<?php

    require("coneccion/conexion.php");


    print("Coneccion exitosa </br>");

$tablacontenido=''; $tabla = "CALL TraerTodos();"; $r= mysqli_query($l, $tabla); if ($r) { while ($reg = mysqli_fetch_object($r)) {

            $tablacontenido= $tablacontenido.'<tr>'.
            '<td>'. $reg->nombre.'</td>'
            .'<td>'. $reg->apellido.'</td>'
            .'<td>'. $reg->usuario.'</td>'
            .'<td>'. $reg->clave.'</td>';
        }
    }
    else
    {
        print "Error en la operacion de tabla </br>";
    }


?>

<table id="tabla1">
    <thead>

        <tr>
            <td>Nombre</td>
            <td>Apellido</td>
            <td>Nombre de Usuario</td>
            <td>Contraseña</td>
        </tr>

    </thead>



<?php

    echo "$tablacontenido";

?>
    
asked by Agustin Coronel 19.10.2018 в 06:48
source

1 answer

0

You should check if the call to the jquery is correct. You can see this in the debug console of the browser because if it is not correct, mark an error.

The jquery you are looking for in the same folder where PHP is. Without this js you can not see the appearance of the table since the jquery.dataTable depends on it.

I re-applied the code without PHP and called the jquery from code.jquery.com to try

<head>
    <meta charset="UTF-8">
    <title>
        Tabla PHP
    </title>
    <script
            src="http://code.jquery.com/jquery-1.11.2.min.js"
            integrity="sha256-Ls0pXSlb7AYs7evhd+VLnWsZ/AqEHcXBeMZUycz/CcA="
            crossorigin="anonymous"></script>
    <link rel="stylesheet" type="text/css"
          href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
    <script type="text/javascript"
            src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"> </script>
    <script type="text/javascript">
        $(document).ready( function ()
        {
            $('#tabla1').DataTable();
        } );
    </script>
</head>
<body>
<table id="tabla1">
    <thead>
    <tr>
        <td>Nombre</td>
        <td>Apellido</td>
        <td>Nombre de Usuario</td>
        <td>Contraseña</td>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>Nombre Contenido 1</td>
        <td>Apellido contenido 1</td>
        <td>Nombre de Usuario contenido 1</td>
        <td>Contraseña contenido 1</td>
    </tr>
    <tr>
        <td>Nombre Contenido 1</td>
        <td>Apellido contenido 1</td>
        <td>Nombre de Usuario contenido 1</td>
        <td>Contraseña contenido 1</td>
    </tr>
    <tr>
        <td>Nombre Contenido 1</td>
        <td>Apellido contenido 1</td>
        <td>Nombre de Usuario contenido 1</td>
        <td>Contraseña contenido 1</td>
    </tr>
    </tbody>
</table>
</body>

It works, so I think your problem is in the call to .

I hope you find it useful.

    
answered by 19.10.2018 в 13:29