Change the style of TABLES mysql html

0

I'm doing a CRUD and I'd like to modify the way the tables look.

Currently the code is:

<?php
$conexion = mysqli_connect( "localhost", "root", "", "bdnutriologo")or
die( "Problemas con la conexión" );

$registros = mysqli_query( $conexion, "select *
                    from tipo_menu")or
die( "Problemas en el select:" . mysqli_error( $conexion ) );

while ( $reg = mysqli_fetch_array( $registros ) )


{
echo "<table>";
echo "<tr><th>ID Menu:</th><td>" . $reg[ 'id_menu' ] . "</td></tr><br>";
echo "<tr><th>Comidas Diarias:</th><td>" . $reg[ 'cantidad_comidas' ] . " 
</td></tr><br>";
echo "<tr><th>Nombre:</th><td>" . $reg[ 'nombre' ] . "</td></tr><br>";
echo "<tr><th>Descripcion:</th><td>" . $reg[ 'descripcion' ] . "</td></tr> 
<br>";


} 

mysqli_close( $conexion );
?>

And it looks like this:

I'd like it to look like this: Make it look like a list AND show the records in a single table

    
asked by Digital Renegade 19.04.2018 в 19:11
source

1 answer

1

You have to take out your table tag from the loop like this:

<?php
$conexion = mysqli_connect( "localhost", "root", "", "bdnutriologo")or
die( "Problemas con la conexión" );

$registros = mysqli_query( $conexion, "select *
                from tipo_menu")or
die( "Problemas en el select:" . mysqli_error( $conexion ) );
echo "<table><thead><tr><th>ID Menu:</th><th>Comidas Diarias:</th>";
echo "<th>Nombre:</th><th>Descripcion:</th></tr></thead><tbody>";
while ( $reg = mysqli_fetch_array( $registros ) )
{    
    echo "<tr><td>" . $reg[ 'id_menu' ] . "</td>";
    echo "<td>" . $reg[ 'cantidad_comidas' ] . "</td>";
    echo "<td>" . $reg[ 'nombre' ] . "</td>";
    echo "<td>" . $reg[ 'descripcion' ] . "</td></tr>     
} 
echo "</tbody></table>";
mysqli_close( $conexion );
?>
    
answered by 19.04.2018 / 19:15
source