Separate return from a table to a Timeline

Asked

Viewed 74 times

0

I am creating a Timeline where there may be more than one user update per day.

I need my return sql to already compare the 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 date and time of change, I would like in a way that I compare the changes made in the same day and put the indicated class so that Timeline appears only on the left or only on the right.

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

To appear on the left side, does not use class, to appear on the right side put the class Inverted"

inserir a descrição da imagem aqui

  • And having two updates on the same date? What would the message look like? Unite the two in the same?

  • @Joãomartins, then he would take Order By by the time of the change

  • Ha, ok, so the goal is, in this case, to keep all of day 7 on the left side and day 8 on the right side?

  • Exactly, sorry for the delay to answer

1 answer

1


First search 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 
   }
}

Browser other questions tagged

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