Consultation of a date between two dates

Asked

Viewed 393 times

0

I needed to consult if a certain date is contained in a date range. Being more specific, in a vehicle control system we have, when we receive a fine, we need to identify the driver who was with a particular vehicle on the day in question.

Example:

$data_saida (registrada quando o veiculo sai)
$data_retorno (registrada quando o veiculo retorna)

$data_infracao = (registrada quando chega a multa)
$placa_veiculo = (registrada quando chega a multa)

What method do I use to confirm according to the time of the violation, who, was with the car by the date, since we have several drivers adastrado? The vehicle was easy as the plate comes in fine and is a unique identifier...

Follow the code I’m running:

<?php
$data = date('Y-m-d');
$hora = date("H:i:s");

$placa = $_POST ['multas'];
$data_i = $_POST ['data_i'];
$hora_i = $_POST ['hora_i'];

$sql = "SELECT * FROM trafego WHERE '$data_i' BETWEEN 'data_s' AND 'data_e' AND placa='$placa'";
$verifica = mysqli_query ($strcon,$sql) or die (mysqli_error());
$row = mysqli_num_rows ($verifica);
    if ($row >=1) {
while ($resultado = mysqli_fetch_array($verifica)){
    $id_trafego = $resultado ['id_trafego'];
    $condutor = $resultado ['condutor'];
    $data_s = $resultado ['data_s'];  
    $hora_s = $resultado ['hora_s'];
    $data_e = $resultado ['data_e'];
    $hora_e = $resultado ['hora_e'];

    echo "<hr/>";
    echo $id_trafego;
    echo "<br/>";
    echo "CONDUTOR:&nbsp;&nbsp;",$condutor;
    echo "<br/>";
    echo "DATA SAÍDA:&nbsp;&nbsp;",date('d/m/Y',strtotime($data_s)),"&nbsp;&nbsp;&nbsp;","HORA DA SAÍDA:&nbsp;&nbsp;",$hora_s;
    echo "<br/>";
    echo "DATA RETORNO:&nbsp;&nbsp;",date('d/m/Y',strtotime($data_e)),"&nbsp;&nbsp;&nbsp;","HORA RETORNO:&nbsp;&nbsp;",$hora_e;
    echo "<hr/>";
    echo "<br/>";
    echo "<br/>";


}
    }else{
        echo "<p><h3>Não existe registro de veículos em tráfego na data da multa.<br/>";
        echo "Verifique a data digitada, e tente novamente</p></h2>";
    }
?>
  • Excuse me, correcting the last paragraph (put in capital letters the correction): What method do I use to confirm according to DATE of the infringement, who, was with the car, since we have several registered drivers? The vehicle was easy as the plate comes in fine and is a unique identifier...

1 answer

0

I wanted to thank you all for your help.

I made a change to the code by placing the second condition WHERE in the case of 'plaque', before the BETWEEN and worked properly. I will paste the changed code below.

The variable $data_i (date of infringement) comes soon after, but in this case now after the 'board'. previously the 'board' condition was at the end.

CORRECTED CODE

$sql = "SELECT * FROM trafego WHERE placa='$placa'AND'$data_i' BETWEEN data_s AND data_e";
$verifica = mysqli_query ($strcon,$sql) or die (mysqli_error());
$row = mysqli_num_rows ($verifica);
        if ($row >=1) {
while ($resultado = mysqli_fetch_array($verifica)){
    $id_trafego = $resultado ['id_trafego'];
    $condutor = $resultado ['condutor'];
    $data_s = $resultado ['data_s'];  
    $hora_s = $resultado ['hora_s'];
    $data_e = $resultado ['data_e'];
    $hora_e = $resultado ['hora_e'];
}

Browser other questions tagged

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