Query of date filter does not give expected result [closed]

1

My intention is to list a series of products, specifying a range of dates of reservation intention, and filtering the products not yet reserved.

$comprobar_reservas_disponibilidad = mysqli_query($con,"SELECT DISTINCT flotaid 
                FROM disponibilidad 
                WHERE ('$fecha_inicio' BETWEEN DESDE AND HASTA) AND ('$fecha_fin' BETWEEN DESDE AND HASTA) ORDER BY flotaid");


$comprobar_prereservas = mysqli_query($con,"SELECT DISTINCT flotaid 
            FROM prereserva 
            WHERE ('$fecha_inicio' BETWEEN DESDE AND HASTA) AND ('$fecha_fin' BETWEEN DESDE AND HASTA) ORDER BY flotaid");

Imagine that the information of the two queries is stored in an array from which the info is extracted.

I use two queries because each of them belongs to a table. In both of them there is reservation information, but each one is filled in one way, that's the same.

How is it possible to query the correct result for a small date range, but not for a large one? The listed result should only be smaller and smaller, since a longer range of dates covering products already booked is requested, is not it?

I use three tables, "pre-book" and "availability" , which are used to store booking data, and "fleet" , where the descriptive information of the ships is stored..name, characteristics, model..etc. The data of the user who makes the reservation from the web, are saved in "pre-booking" until a few days pass or the admin of the web passes it through another program to the table "availability", which is the definitive reservations.I need fill in "pre-booking" with the data of the range of dates to reserve, boat, user to reserve.

step link to complete file: "Complete code"

and image of what a range of dates returns: link

example : boats not available between the days of 11/25/2016 and 11/25/2016: Ids 8,15,17, so the others are listed, those available

What I need in a query (which I will use twice) to get the ids of the boats AVAILABLE, and filter the NOT AVAILABLE, which will be shown in a print / echo to know what has been filtered.

    
asked by Víc M.R. 24.10.2016 в 10:02
source

1 answer

0

Try doing the queries in the following way:

$fechaDesde = '2015-10-24';
$fechaHasta = '2016-10-24';

$consulta = 'SELECT DISTINCT flotaid 
    FROM disponibilidad 
    WHERE fecha BETWEEN "'.$fechaDesde.'" AND "'.$fechaHasta.'"
    ORDER BY flotaid ASC';
$comprobar_reservas_disponibilidad = mysqli_query($con, $consulta);

$consulta = 'SELECT DISTINCT flotaid 
    FROM prereserva 
    WHERE fecha BETWEEN "'.$fechaDesde.'" AND "'.$fechaHasta.'"
    ORDER BY flotaid ASC';
$comprobar_prereservas = mysqli_query($con, $consulta);
    
answered by 24.10.2016 в 14:56