display data in the header of a table

0

I would like to show data in the header of a table, but I can not show it to me as I want; since this field to be shown in the header is called from the attached bd an image of how the data should be displayed and my source code.

the line to show in the header would be {$linea['hora_sorteo']} which is the one marked in red in the image

 <?php
    $sql2 = "SELECT 
    animalitos.id,
    animalitos.portada,
    animalitos.nombre,
    animalitos.numero,
    animalitos.color,
    animalitos.grupo,
    animalitos.numero_letras,
    resultado.id,
    resultado.fk_animalitos,
    resultado.fk_hora_sorteo,
    resultado.fecha,
    hora_sorteo.id,
    hora_sorteo.hora_sorteo
           FROM animalitos 
                INNER JOIN resultado ON animalitos.id=resultado.fk_animalitos  
                INNER JOIN hora_sorteo ON resultado.fk_hora_sorteo=hora_sorteo.id
                WHERE resultado.fecha BETWEEN CURRENT_DATE()-7 AND CURRENT_DATE()-1 ORDER BY resultado.id, resultado.fk_hora_sorteo  DESC ";

       $consulta = $DB_con->prepare($sql2);
       $consulta->execute();
       if($consulta->rowCount() > 0){
       $i=1;


    while ($linea = $consulta->fetch(PDO::FETCH_ASSOC)) {

    echo "<table  class='striped responsive-table centered'>";
    echo "<thead>
    <tr>
    <th data-field='Operaciones'>{$linea['hora_sorteo']}</th>
    </tr>
    </thead>";

    echo "<tr>
    <td align=center>{$linea['numero']} - {$linea['nombre']}</td>
         </tr>";

       $i++;
      }
    }

   else

   echo "<div class='col s12 card-panel yellow darken-2 center'>
   <h5 class='black-text text-darken-2 center CONDENSED LIGHT5'>
   ¡ Advertencia: No se ha encontrado ningún registro !
   </h5>
   </div>";
   echo "</table>";
   ?>
    
asked by yoclens 03.06.2017 в 06:14
source

1 answer

0

I could solve the annex code:

<?php
$consulta = $DB_con->query("SELECT * FROM hora_sorteo");
for ($set = array (); $row = $consulta->fetch(PDO::FETCH_ASSOC); $set[] = $row);
?>
<table  class='striped responsive-table centered'>
<thead>
<tr>
<?php for($i=0;$i<count($set);$i++){
echo "<th>" . $set[$i]['hora_sorteo'] . "</th>"; 
}?>
</tr>
</thead>
    
answered by 05.06.2017 / 01:32
source