Check days from the 1st to the 5th of each month

0

I comment, I need the system on the days of 1 to 5 of each month to verify if people from a condominium made the payment, but to place them in default. I was researching and I believe that I date period with date interval, it is the closest thing to that function, for the moment I have the following, however, I do not do what I requested, I hope you can help me.

The date value of the pago_p table is in date

format

<?php
require_once('../conexion.php');
$hoy = getdate();
$begin = new DateTime( '2018-08-01' );
$end = new DateTime( '2018-08-31' );


$interval = new DateInterval('P1M');
$daterange = new DatePeriod($begin, $interval ,$end);

foreach($daterange as $date){
    $sql = "SELECT * FROM pago_p"; 
    $res = mysqli_query($conexion,$sql);
    
    while($resultado = mysqli_fetch_array($res)){
    if(["pago"]==NULL {

    echo '<script> alert("No realizaste el pago en la fecha determinada"); </script>';

    }
}
?>
    
asked by Anderson Rey 12.08.2018 в 14:59
source

2 answers

0

Would it be something like that?

$año_actual = date("Y");
$mes_actual = date("m");
//Fecha adaptada para MySQL.
$inicio = $año_actual."-".$mes_actual."-"."01"." 00:00:00";
$fin = $año_actual."-".$mes_actual."-"."05"." 00:00:00";

$sql = "SELECT * FROM pago_p WHERE campo_fecha BETWEEN '".$inicio."' AND '".$fin."'"; 
$res = mysqli_query($conexion,$sql);
//Resultado contiene todos los que pagaron en tiempo y forma, para encontrar lo inverso se puede negar la consulta.
$resultado = mysqli_fetch_array($res);

Actually, I think that the question is perhaps wrong, because if the system should automatically check "something" on certain days, it should be done with a cronjob.

    
answered by 12.08.2018 / 16:39
source
1

Reading your code, and using your syntax, create an algorithm that will do what you need, validate the 5 days of each month if the payment was made.

then it would be like this:

<?php
    require_once('../conexion.php');
    // $hoy = getdate();
    //fecha inicial
    $begin = new DateTime( '2018-08-01' );
    //fecha final que comprede que debe evaluar los primeros 5 dias 
    $end = new DateTime( '2018-08-05' );
    //agregamos un dia mas para que cuente el 5 en la otra fecha ponemos hasta el 6
    $end = $end->modify( '+1 day' ); 

    //Creamos el intervalo de tiempo para que sea por cada dia 
    $interval = new DateInterval('P1D');
    $daterange = new DatePeriod($begin, $interval ,$end);

    $alerta="";
    //recorremos la varaible que ahora almacena el rango entre 1 - 5
    foreach($daterange as $date){
        //creamos el formato de la fecha
        $fecha_dia= $date->format("Ymd");
        //hacemos la consulta con la condicion de la fecha para validar los correspondientes dias que se necesitan
        $sql = "SELECT * FROM pago_p WHERE fechas_campo =' $fecha_dia'"; 
        $res = mysqli_query($conexion,$sql);

        while($resultado = mysqli_fetch_array($res)){
            //verificamos que en cada fila el campo "pago" no este vacio
            if(!empty($resultado["pago"])) {
                //si no esta vacio entonces realizo el pago
                //y damos valor a una variable
                $alerta="si";
            }
        }

        if ($alerta=="si") {
            //despues del ciclo imprimimos la alerta para que en cada ciclo no la repita
            echo '<script> alert("No realizaste el pago en la fecha determinada"); </script>';
        }
?>

I hope you serve and mark it xD ... ReNiceCode ...

    
answered by 12.08.2018 в 16:41