Show mysql data in a table with php

0

I have an input where I put a query and it returns the data of the query, but I want the data that I returned to be in a table so that they can be visualized better. Nowadays I get something like this:

first name first name last name first name

and I would like it to come out in a table or something in order to better differentiate the data. This is the code I have to execute the query and show the data.

<?php  
session_start();



$conexion = new mysqli("localhost", "root", "", "bbdd");
if ($conexion->connect_errno) {
    echo "Fallo al conectar a MySQL: (" . $conexion->connect_errno . ") " . $conexion->connect_error;
}


$consultaa=$_POST["consultaa"];

    $queryy = mysqli_query($conexion, "$consultaa");


    if (!$queryy){
       die('Error: ' . mysqli_error($conexion));
    }
    if(mysqli_num_rows($queryy) > 0){
       $response='success';
    } 

    $column=mysqli_num_fields($queryy);
 while ($row = mysqli_fetch_array($queryy))

 {
    for ($i=0; $i < $column; $i++) { 

?>  
 <td><?php echo $row[$i];?></td>

 <?php      
    }


 }

?>  
    
asked by francisco 17.02.2018 в 13:12
source

1 answer

1

In the part where you show the data:

while ($row = mysqli_fetch_array($queryy)) {
    for ($i=0; $i < $column; $i++) {
        ?>
        <td><?php echo $row[$i]; ?></td>
        <?php
    }
}

You must modify it so that the structure of the complete table is created, in your code, you only indicate that the HTML td tags are created and therefore, you are missing the table and the tr, it would be something like this:

echo "<table>"; // Creas la tabla
while ($row = mysqli_fetch_array($queryy)) {
    echo "<tr>"; // Por cada fila
    for ($i=0; $i < $column; $i++) {
        ?>
        <td><?php echo $row[$i]; ?></td>
        <?php
    }
    echo "</tr>";
}
echo "</table>";

Then you just have to give it the format you want with CSS.

    
answered by 17.02.2018 / 13:54
source