Select search by sampling periods

Asked

Viewed 45 times

1

I am creating an application, and in case this application will have several filters for the user.

One of this filter is the famous search by date. In this case, the user searches between the two desired dates and chooses 3 types of sampling of this data, or they will appear Daily, or weekly or monthly. In this case, the daily sampling I managed to do, but I stalled on the monthly. In this case, I did a counter in strtotime for the daily sampling. I went to use the same technique for the weekly but if someone chose a period other than the multiple of 7, it does not show the rest. I tried to do a rest scheme, but it didn’t work, leaving only taking the sampling of the exact periods. And in that case, I would need to do the sampling with the broken period. Ex: If the user chooses a period of 10 days with the weekly sampling, the first consultation will be 7 days and the second will be 3 days.

Below is the excerpt from the Daily and Weekly Code.

 //Período Diário
                if($periodo == "Diaria") { 
                    $periodo1 = $data_ini_;
                    $periodo2 = $data_fim_;




                        while($periodo1 <= $periodo2) { 


                            //echo "<BR>DENTRO DO LOOP<BR>";
                            //echo $periodo1."<BR>";
                            //$periodoDiario = $periodo1; 
                            $saidaPeriodo = "Dia $periodo1";

                            $where = "BETWEEN '$periodo1' AND 
'$periodo1 23:59:59')";
                            //echo $where."<BR>";

                            $consulta = "SELECT GITEC, SUM (DATEDIFF 
 (second,INICIO,DT_FECHAMENTO_OCORRENCIA)) as Soma_tempo, AVG 
 (DATEDIFF (second,INICIO,DT_FECHAMENTO_OCORRENCIA)) Media_tempo
                            FROM [readb004].[dbo].
 [reavw002_ocorrencias_historicos_cgr] 
                            WHERE ([INICIO]  $where AND $where1 
  $where2 $where3 $where4 AND ([USUARIO_REGISTRO] NOT IN 
  ('SISTEMA','Remedy ...','CETEC72' )) AND ([QUEDA_MASSIVA] = 0)
                            GROUP BY  GITEC  
                            order by  GITEC DESC";


                            //AND $where1 $where2 $where3

                            //echo $consulta."<BR>";


                            $periodo1 = date("Y-m-d", strtotime("+1 
   day",strtotime($periodo1))); 








                //echo $consulta; 







                //BETWEEN '$data_ini_' AND '$data_fim_

                    //Formata o resultado 

                    $result = $sqlq->execute($consulta); 
                        while(!$result->EOF) { 
                            $gitec = $result->Fields['GITEC']->Value; 
                            $soma_tempo = $result-
 >Fields['Soma_tempo']->Value; 
                            $media_tempo = $result-
 >Fields['Media_tempo']->Value; 


                            $horas_gitec = floor($soma_tempo/ 3600); 
                            $minutos_gitec = floor(($soma_tempo - 
   ($horas_gitec * 3600)) / 60);    
                            $segundos_gitec = floor($soma_tempo%60); 
                            $hora_result = 
   $horas_gitec.':'.$minutos_gitec.':'.$segundos_gitec;
                            $htotal_msg = 
  date("H:i:s",strtotime($hora_result));    

                            $horas_gitec2 = floor($media_tempo / 
  3600);
                            $minutos_gitec2 = floor(($media_tempo - 
  ($horas_gitec2 * 3600)) / 60);        
                            $segundos_gitec2 = floor($media_tempo%60); 
                            $hora_res = 
 $horas_gitec2.':'.$minutos_gitec2. ":".$segundos_gitec2;
                            $hora_msg = 
    date("H:i:s",strtotime($hora_res)); 



                            $consultaData = "SELECT [gitec],
  [data_migracao] FROM [Ocorrencias].[dbo].[Tb_data_migracao] WHERE 
  [gitec] ='$gitec'"; 
                            //Executa a consulta    
                            $resGitec = $sql->execute($consultaData); 
                                $gitNova = $resGitec->Fields['gitec']-
  >Value; 
                                $data_migracao = $resGitec-
     >Fields['data_migracao']->Value; 

                                $dataTeste = $data_migracao; 

                                //echo $dataTeste."<BR>"; 





                        echo "
                            <tr>
                                <td>$gitec</td>"; 

                            if($dataTeste > $periodo1) {        

                        echo "<td>$saidaPeriodo</td>
                              <!--<td>$htotal_msg</td>-->
                              <td>$hora_msg</td>
                              <!--<td>-</td>-->
                              <td>-</td>
                              <td>-</td>
                            </tr>
                        "; } else { 

                            echo "<td>$saidaPeriodo</td>
                              <!--<td></td>-->
                              <td>-</td>
                              <!--<td>$htotal_msg</td>-->
                              <td>$hora_msg</td>
                              <td>-</td>"; 
                        }   



                    $result ->MoveNext(); } 
                    } } else if ($periodo = "Semanal") { 

                            $periodo1 = $data_ini_;
                            $periodo2 = $data_fim_;

                            echo $periodo1."<BR>"; 
                            echo $periodo2."<BR>"; 

                            echo "<BR>";        

                                while($periodo1 <= $periodo2) { 


                                    echo "<BR>DENTRO DO LOOP<BR>";
                                    echo $periodo1."<BR>";
                                    $saidaPeriodo = ""; 

                                    $periodo1 = date("Y-m-d", 
              strtotime("+7 day",strtotime($periodo1))); 

In case what I could do to that is right Weekly sampling?

No answers

Browser other questions tagged

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