I'm creating an application, and in case this application will have multiple filters for the user.
One of this filter is the famous search by date. In this case, the user performs the search between the two desired dates and chooses 3 types of sampling of this data, or they will appear Daily, either weekly or monthly. In the case, the daily sampling I was able to do, however I caught on the monthly. In this case, I made a counter at strtotime for daily sampling. I was using the same technique for the weekly but if someone chooses a different period than the multiple of 7, it does not show the rest. I tried to make a remainder scheme, but it did not work, leaving only sampling the exact periods. And in this case it would need to be sampled 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 daily and weekly code snippet.
//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 could I do that is sampling Weekly for right?