Page Calendar By Week

0

I am developing a Specific Agenda for a client but I'm not sure how to page the calendar per week. The schedule works much more I 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;

Note that select I do

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

Then he returns me the agendas for this week from 2015/01/05 to 2015/01/10.

How can I page this from 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 Thanks to everyone for help

    
asked by anonymous 14.01.2015 / 02:34

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.
$ proximaData = end date of the 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 I have helped you:)

    
14.01.2015 / 05:47