Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

365
Visualizações
Display Records by date via PHP using table

The first image are my records in my database, 'enr_biometrics_id' is a user_id i just name it like that. nevermind the 'log_no'

datatable datatable

Now, I want to display the records of enr_biometrics_id = '000000001' from date 2021-07-01 - 2021-07-15, just like the image below using and display blanks on no record on the date 2021-07-01 - 2021-07-15. Thanks for the help in advance!

2nd image

I have a code right now:

    <?php include('config/config.php'); ?>
<table border="1">
<tr>
    <th>Log Date</th>
    <th>Logs</th>
    <th>Logs</th>
    <th>Logs</th>
    <th>Logs</th>
    <th>Logs</th>
</tr>
<?php
$start_period = "2021-07-01";
$end_period = "2021-07-15";

date_default_timezone_set('UTC');

while (strtotime($start_period) <= strtotime($end_period)) {
    
?>
<tr>
    <td><?php echo "$start_period"; ?></td>
    <?php
    $logs_query = mysqli_query($conn, "SELECT * FROM tb_daily_time_record WHERE date_added BETWEEN '$start_period' AND '$end_period' AND enr_biometrics_id='000000001' ")or(die(mysql_error()));
        
            while($row_logs = mysqli_fetch_assoc($logs_query)){
                $date_logs = $row_logs['date_added'];
                $t_logs = $row_logs['time_log'];
    ?>
        <td>
        <?php 
            echo $t_logs;
        ?>
    </td>
    <?php 
        }
    ?>
</tr>
<?php 
 $start_period = date ("Y/m/d", strtotime("+1 days", strtotime($start_period)));
}
?>
<tr>
</table>

Getting a result like this MyCoderightnow

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This would be my workaround on the information you are giving. It's probably posible to optimise thise but it gives a good idea of a solution.

Short sum, i check if the current row has the same string as the row before, if this isnt the case i create a new row

$result = 'SELECT * FROM table'; // query .. 

$checkdate='';

echo '<table>';
foreach ($result as $row) {
  if ($row['date_added'] != $checkdate) {
    $checkdate = $row['date_added'];

    echo '</tr>
    <tr>
    <td>'.$row['time_log'].'</td>
    <td>'.$row['time_log'].'</td>';
    continue;
  }
  echo '<td>'.$row['time_log'].'</td>';
} 
echo '</tr></table>';
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda