problems showing results in a table

0

I have a problem when showing records in my table the problem is the following: in the header of the table I show the hours that would be eight in total and below the header the results of the numbers that have come out are shown according to the time and day, but the problem arises that the first week of Thursday recorded some data and now the second week of Thursday you must register the other data of that same day but I am still showing in the same row when it should be shown below because it is supposed to be the same day but different results attached an image and to show how it should look and my error currently presented.

source code

<div id="test5" class="center-align light">

    <?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>"; //muestra las horas de jugada
   }?>
   </tr>
    </thead>

    <?php
    $consulta2 = $DB_con->query("SELECT 
    animalitos.id,
    animalitos.numero,
    resultado.id,
    resultado.fk_animalitos,
    resultado.fk_hora_sorteo,
    resultado.fk_dias,
    resultado.fecha,
    hora_sorteo.id,
    hora_sorteo.hora_sorteo,
    dias.id,
    dias.dias
           FROM animalitos 
                INNER JOIN resultado ON animalitos.id=resultado.fk_animalitos  
                INNER JOIN hora_sorteo ON resultado.fk_hora_sorteo=hora_sorteo.id
                INNER JOIN dias ON resultado.fk_dias=dias.id
                WHERE resultado.fk_dias='5'  ORDER BY resultado.id ");
           for ($set2 = array (); $row = $consulta2->fetch(PDO::FETCH_ASSOC); $set2[] = $row);
              ?>
          <tr>
         <?php for($b=0;$b<count($set2);$b++){
         echo "<td>" . $set2[$b]['numero'] . "</td>"; //muestra los 
         resultados de los numeros
           }?>
          </tr>
        </table>
        </div>
    
asked by yoclens 10.06.2017 в 20:55
source

2 answers

0

the solution is this

<div id="test6" class="center-align light">

    <?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>

   <?php
    $consulta2 = $DB_con->query("SELECT 
   animalitos.id,
   animalitos.numero,
   resultado.id,
   resultado.fk_animalitos,
   resultado.fk_hora_sorteo,
   resultado.fk_dias,
   resultado.fecha,
   hora_sorteo.id,
   hora_sorteo.hora_sorteo,
   dias.id,
   dias.dias
           FROM animalitos 
                INNER JOIN resultado ON animalitos.id=resultado.fk_animalitos  
                INNER JOIN hora_sorteo ON resultado.fk_hora_sorteo=hora_sorteo.id
                INNER JOIN dias ON resultado.fk_dias=dias.id
                WHERE resultado.fk_dias='6'  ORDER BY resultado.id ");
    for ($set2 = array (); $row = $consulta2->fetch(PDO::FETCH_ASSOC); $set2[] = $row);
    ?>
    <?php 

    $set2 = array_chunk($set2, 8);
    foreach($set2 as $set){
    echo "<tr>";
    foreach($set as $v){
    echo "<td>" . $v['numero'] . "</td>"; 
     }
     echo "</tr>";
     }

      ?>
      </table>
      </div>
    
answered by 12.06.2017 / 04:40
source
0

This should solve your problem, but I think you should rethink the way you get the data.

       for ($set2 = array (); $row = $consulta2->fetch(PDO::FETCH_ASSOC); $set2[] = $row);    
       echo '<tr>';    
       for($b=0;$b<count($set2);$b++){
            if ($b%8==0){
                 echo '</tr>';
                 echo '<tr>';
             }
           echo "<td>" . $set2[$b]['numero'] . "</td>";
       }
       echo '</tr>';
    
answered by 10.06.2017 в 21:28