Calendar Per Week Page

Asked

Viewed 453 times

0

I am developing a Specific Client Schedule But I’m not sure how to schedule a week. The schedule works much more do not know how to page now

date_default_timezone_set('America/Sao_Paulo');
$data1 = date('d/m/Y');
$hora1 = date('H:i:s');


include'../assets/config.php";


$sql ="SELECT * FROM os where status2 <> 'Fechado' AND start1 BETWEEN '2015/01/05'       
AND '2015/01/12' ";
$resultado = mysql_query($sql) or die( mysql_error());
while ($linha = mysql_fetch_assoc($resultado)) {
$id1 = $linha["id1"];              
$nome = $linha["nome_cliente"];
$nome_tec = $linha["nome_tec"];
$tecnico = $linha["nome_tecnico1"];


$start1 = $linha["start1"];
$d1 = substr($start1, 0, 10 );
$t = '&nbsp;';
$d2 = substr($start1, 11, 5 );
$start = $d1.$d2;
$data1 = implode("/",array_reverse(explode("-",$d1)));
$datal = $data1.$t.$d2;

Notice that the select I do

$sql ="SELECT * FROM os where status2 <> 'Fechado' AND start1 BETWEEN '2015/01/05'  
AND '2015/01/12' ";

Then it returns me the agendas of this week 2015/01/05 to 2015/01/10.

How can I page this 2015/01/05 to 2015/01/10. ---> Next 2015/01/11 to 2015/01/17 --------> Next 2015/01/18 to 2015/01/24

From now on I thank you all for your help

1 answer

2


Assuming your date is in the format: Y-m-d Your sql for the search would be:

$sql ="SELECT * FROM os where status2 <> 'Fechado' AND start1 BETWEEN ".$dataRecebida." AND ".$proximaData." ";

Follow the commented code:

$dataReceived = start date of the week.
$next Date = end date of week.

<?php

    // Recebe a data do link caso exista. Do contrario assume a data atual.
    if(isset($_GET['date'])){
        $dataRecebida = $_GET['date'];
    }else{
        $dataRecebida = date("Y-m-d");
    }

    // Data atual 
    $date = date("Y-m-d");

    // DateTime atual
    $dataAtual = new DateTime($date);

    // DateTime da data recebida
    $dataAtualCalendario = new DateTime($dataRecebida);

    // Calcula a diferença entre a data atual e a data recebida
    $interval = $dataAtual->diff($dataAtualCalendario);
    $diff = intval($interval->format('%R%a'));

    // Define a string usada para o strtotime baseada na diferença anterior
    // adicionando +7 para semana seguinte
    // subtraindo -7 para semana anterior
    $valProxima = ($diff+7)." days";
    $valAnterior = ($diff-7)." days";

    // Calcula a data da proxima semana
    $proximaData = date('Y-m-d', strtotime($valProxima));

    // Calcula a data da semana anterior
    $dataAnterior = date('Y-m-d', strtotime($valAnterior));


    // Exibe os links para teste
    echo "Data Anterior: <a href='?date=".$dataAnterior."'>".$dataAnterior."</a>";
    echo "<br/>Data atual: ".$dataRecebida;
    echo "<br/>Próxima data: <a href='?date=".$proximaData."'>".$proximaData."</a>";

I hope you helped him :)

Browser other questions tagged

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