Problems generating a table [closed]

0

I'm having a hard time making a table. Could someone make a table that shows the times an employee did during the month? the idea would be to show the beating of employees during the month.

In my bank would have the table that would keep these beats of the employees:

tag
batida_id (int) is the id of the hit contributor_id (int) (time) is the time of the strike eg: 07:30:00, 12:00:00.
date (date) is the date
type (char) is the type of hit entry or exit.

Example:  if an employee has the following hits:

hit_id => 1 contributor_id = > 1 data = > 06/01/2016 hit = > 07:30 type = > entrance
hit_id => 2 collaborator_id = > 1 data = > 06/01/2016 hit = > 12:00 Type = > exit hit_id => 3 collaborator_id = > 1 data = > 06/01/2016 hit = > 13:30 type = > entrance
hit_id => 4 collaborator_id = > 1 data = > 06/01/2016 hit = > 17:00 type = > exit

The table should look like this:

I was able to do only one part of the table, I can not logically show the beats in front of the dates.

<table class="table table-striped">
  <tr>
  <th>Data</th>
  <th>Dia Semana</th>
  <th>Ocorrências</th>
  </tr>  <br />

    <?php


    $diasSemana[1] = 'Segunda-feira';
    $diasSemana[2] = 'Terça-feira';
    $diasSemana[3] = 'Quarta-feira';
    $diasSemana[4] = 'Quinta-feira';
    $diasSemana[5] = 'Sexta-feira';
    $diasSemana[6] = 'Sábado';
    $diasSemana[7] = 'Domingo';


    for($dias = 1; $dias <= date('t',strtotime('2016-06')); $dias++)

    {
    echo "<tr>";
    echo "<th>".$dias."</th>" . "<th>".$diasSemana[date('N', strtotime("2016-06-$dias"))] ."</th>" . "<th>";


        }


   echo "</tr>";

?>    
             </table>

Could anyone help me?

    
asked by anonymous 27.06.2016 / 21:57

1 answer

1
<?php
    # valor que vem do formulario (se houver)
    $colaborador = 1;

    # todos os resultados por ordem de dia e hora (não importa a entrada e saída) de uma matricula (se for de todos, retire o WHERE)
    $resultado = "SELECT * FROM tabela WHERE colaborador = {$colaborador} 
    ORDER BY dia ASc, HOUR(hora) ASC";

    # se vier um array valido
    if (is_array($resultado) && count($resultado) >0)
    {
        # uma variável para armazenar as horas
        $dia_hora = array();
        foreach($resultado as $key => $value)
        {
            # agrupar dia e hora
            $dia_hora[$value['dia'][] = $value['hora'];
        }
        # construir a tabela
        echo "<table>" . PHP_EOL .
        "<tbody>";
        foreach($resultado as $key => $value)
        {
           echo "<tr>" . PHP_EOL .
                "<td>{$value['dia']</td>" . PHP_EOL;
            # aqui é a forma (que eu achei) para imprimir a entrada e saída na mesma linha e dividir as mesmas por coluna
            $dia[$value['dia'][] = $value['hora'];
            foreach($dia_hora[$value['dia']] as $dia => $hora)
            {
               # 0 (entrada)
               # 1 (saída) 
               echo "<td>{$hora[0]}</td>" . PHP_EOL .
               "<td>{$hora[1]}</td>" . PHP_EOL;
            }
            echo "</tr>";
        }
        echo "</tbody>" . PHP_EOL .
        "</table>";
    
28.06.2016 / 21:10