Separate return from a table to a timeline

0

I'm creating a timeline where there can be more than one user update per day.

I need my return sql already compare dates and I can separate

$sql = "SELECT * FROM tb_timeline JOIN responsaveis ON id_responsavel = feito_timeline WHERE  para_timeline = '".$_SESSION['id_responsavel_matricula']."' ORDER BY data_timeline ASC ";

These updates record a LOG in a table with what was changed and the change date and time, I would like it to compare the changes made on the same day and put the indicated class so that the timeline appears only in the left or right only.

In the image I put for each log appeared one on one side and another on another, but I would like to compare the dates EX: 2018-08-07 appeared on one side and 2018-08-08 appears from another and so on

To appear on the left side, does not use class, to appear on the right side I place the class inverted

    
asked by anonymous 08.08.2018 / 01:26

1 answer

1

First look up the dates with records:

  SELECT distinct data_timeline  //converter o timestamp para data (dd/mm/yyy ou outro formato apenas de dada)
   WHERE  para_timeline = '".$_SESSION['id_responsavel_matricula']."' 
ORDER BY data_timeline order by data_timeline asc;

After having the dates in an array you can fetch all the records of this date.

 $datas = array('01/08/2018', '02/08/2018'); //resultado da query acima
 foreach($datas as $key => $data){

     //define a classe do box da timeline
     $class = $key % 2 ? '' : 'inverted'; 

     //retornar todos os registros da data 
     $sql = "SELECT * 
               FROM tb_timeline 
               JOIN responsaveis 
                 ON id_responsavel = feito_timeline 
              WHERE para_timeline  = '" .$_SESSION['id_responsavel_matricula'] . "' 
                AND data_timeline  = '" . $data . "' 
           ORDER BY data_timeline  ASC";

    //executa a query e traz os resultados da data em uma variavel ($resultados)

   //percorre os itens da tb_timeline na data atual do primeiro loop ($datas)
   foreach($resultados as $idx => $timeline){
   ?>
      <div class="<?php echo $class ?>">
         <!-- conteudo do item da timeline -->
      </div>
   <?php 
   }
}
    
09.08.2018 / 03:24