View 6 previous days

0

Good morning, I'm a beginner in php and I have a problem, someone can help me ...

The code below has the function of showing all the week's due dates for payment of monthly payments. Only he finds the day of Saturday (last day of the week) and shows the 6 days before him.

The problem happens when Saturday falls on the 1st or 2nd of the following month, then it will calculate day 1 minus 6 and will not give me any results. Did you understand? Can anyone help me with this?

Follow my code ..

<?php
    $seleciona = mysql_query("SELECT anoselecionado FROM anoselecionado LIMIT 1");

    while($ln = mysql_fetch_array($seleciona)){
        $anoselecionado = $ln['anoselecionado'];
    } 
?>

Remaining:

<?php

    $dataatual = date('d/m/y');
    $partes = explode("/", $dataatual);
    $diaatual = $partes[0];
    $mesatual = $partes[1];
    $anoatual = "20".$partes[2];

    if ($mesatual == "1"){$essemes = 'jan';};
    if ($mesatual == "2"){$essemes = 'fev';};
    if ($mesatual == "3"){$essemes = 'mar';};
    if ($mesatual == "4"){$essemes = 'abr';};
    if ($mesatual == "5"){$essemes = 'mai';};
    if ($mesatual == "6"){$essemes = 'jun';};
    if ($mesatual == "7"){$essemes = 'jul';};
    if ($mesatual == "8"){$essemes = 'ago';};
    if ($mesatual == "9"){$essemes = 'setembro';};
    if ($mesatual == "10"){$essemes = 'outubro';};
    if ($mesatual == "11"){$essemes = 'nov';};
    if ($mesatual == "12"){$essemes = 'dez';};

    $sabado = 6; //sabado = 6º dia = fim da semana.
    $dia_atual=date('w'); //pego o dia atual
    $dias_que_faltam_para_o_sabado = $sabado - $dia_atual;

    $inicio = strtotime("-$dia_atual days");
    $fim = strtotime("+$dias_que_faltam_para_o_sabado days");

    $primdiasemana = date('d',$inicio); //data inicial
    $ultmodiasemana = date('d',$fim); //data final

    $seleciona = mysql_query("SELECT * FROM mensalidades WHERE (data_pagamento BETWEEN '".$primdiasemana."' and '".$ultmodiasemana."') and ano = ".$anoselecionado." and $essemes = 0 ORDER by id DESC");
    $conta = mysql_num_rows($seleciona);
    if($conta <= 0){
        echo "<center><div><h3>Não existem mensalidades pendentes com vencimento esta semana</h3></div></center>";
    }else{
        echo "
        <table class='table table-bordered' id='tabela-mensalidades'>
            <thead>
                <tr style='backgroud-color: #2D335B'>
                    <th style='width: 200px'>Aluno</th>
                    <th>Vencimento</th>
                    <th>Status</th>
                    <th>Serviço</th>
                    <th>Valor</th>
                </tr>
            </thead>";

        while($ln = mysql_fetch_array($seleciona)){
            $id = $ln['id'];
            $clientes_id = $ln['clientes_id'];
            $servico_id = $ln['servico_id'];
        }
    }
?>
    
asked by anonymous 01.12.2018 / 18:14

0 answers