Go through select function (mysql) in html

0

Good I have the following function in a PHP file I create the following function, which I want to go through to show the records in an html as it is possible to do it. Greetings

function mostrarAreas(){

  $consulta = "SELECT * FROM area";
  $conexion = conectarServidor();
  $query = $conexion->query($consulta);
  while ($fila = $query->fetch_assoc()) {

  }  

}
    
asked by Felipe Larraguibel 13.11.2018 в 18:53
source

3 answers

0

asi:

function mostrarAreas(){

    $consulta = "SELECT * FROM area";
    $conexion = conectarServidor();
    $query = $conexion->query($consulta);
    while ($fila = $query->fetch_assoc()) {
    echo "<pre>los campos son: {$fila['nombre_campo']} {$fila['otro_Campo']} y el {$fila['id_ejemplo']}</pre>";

    }
  }
    
answered by 13.11.2018 в 18:59
0

You can create a table and place the data in it:

...
echo "<table border='1'>
<tr>
<th>Nombre del campo 1 de area</th>
<th>Nombre del campo 2 de area</th>
</tr>";

while($fila = $query->fetch_assoc())
{
echo "<tr>";
echo "<td>" . $fila['nombreCampo1'] . "</td>";
echo "<td>" . $fila['nombreCampo2'] . "</td>";
echo "</tr>";
}
echo "</table>";
...
    
answered by 13.11.2018 в 19:01
0
Esto es como lo muestro a lo bruto 
 $consulta = "SELECT * FROM area order by id_area asc";
                                                $conexion = conectarServidor();
                                                $query = $conexion->query($consulta);
                                                while ($fila = $query->fetch_assoc()) {
                                                $id_area =$fila['id_area'];


                    ?>

                                            <div class="panel panel-default">
                                                <div class="panel-heading">
                                                    <h4 class="panel-title">
                                                        <a class="accordion-toggle accordion-toggle-styled collapsed" data-toggle="collapse" data-parent="#accordion3" href="#<?php echo
                                                        $fila['id_area']; ?>"> <?php echo $fila['nombre_area'];  ?></a>
                                                    </h4>
                                                </div>
                                                <div id="<?php echo $fila['id_area'];  ?>" class="panel-collapse collapse">
    
answered by 13.11.2018 в 19:11