Problems in generating a table

Asked

Viewed 86 times

0

I’m having a hard time making a table. Could someone make a table that shows the times an employee made during the month? the idea would be to show the employee beats during the month.

In my bank would have the table that would keep those employee beats:


markings
batida_id (int) is the id of the beat
collaborator (int) is the official’s registration
registration (time) is the time of the beat ex: 07:30:00, 12:00:00..
date (date) is the date of the strike.
guy (char) is the type of incoming or outgoing hit.


Example: if an employee has the following strikes:

batida_id =>1 collaborator_id=> 1 date => 01/06/2016 beat => 07:30 type => input
batida_id =>2 collaborator_id=> 1 date => 01/06/2016 beat => 12:00 type => output
batida_id =>3 collaborator_id=> 1 date => 01/06/2016 beat => 13:30 type => input
batida_id =>4 collaborator_id=> 1 date => 01/06/2016 beat => 17:00 type => output

the table would have to look like this:
inserir a descrição da imagem aqui

I managed to make only a part of the table, I can not make the logic to 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 someone help me?

  • Writing HELP, HELP, PLEASE does not make the question more urgent, everyone sees here needing help, writing HELP and HELP is totally redundant, be objective when writing. Take it as a constructive criticism. (I’ve already edited the title)

  • Another thing the "stack snippet" is obviously used to run javascript, html and css, ie front-end, there is no reason to use stacksnippet to put php, c++, java, c#, this will never work. Read Help and learn how to use text markup http://answall.com/help/formatting --- Help is for those questions. And please take it as a constructive criticism. (I’ve already removed the snippet stack)

  • Bro, hand me the select you’re doing

  • that’s the problem, like how I do this kind of sql?

  • And there’s already the bank and the tables?

  • Already exists the bank and the table...

  • I was trying here but no chance, I can’t bring the appointments in front of the date

Show 2 more comments

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>";
  • William, I tried to use your code I adapted to mine here but it’s not working :/

  • Group day and time $dia_hour[$value['day']][] = $value['hour']; made wrong code, missed a ] at the end. Sorry. Try again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.