I have a parking reservation program with table
| id | sala | tavolo | data | valore | id_prenotazione |
|---|---|---|---|---|---|
| 9993 | ROMA | 1 | 2022-06-11 | 1 | NULL |
| 9994 | ROMA | 1 | 2022-06-12 | 1 | NULL |
| 9995 | ROMA | 1 | 2022-06-13 | 1 | NULL |
| 9996 | ROMA | 1 | 2022-06-14 | 1 | NULL |
| 9997 | ROMA | 1 | 2022-06-15 | 1 | NULL |
| 99933 | ROMA2 | 1 | 2022-06-11 | 1 | NULL |
| 99944 | ROMA2 | 1 | 2022-06-12 | 1 | NULL |
| 99955 | ROMA2 | 1 | 2022-06-13 | 1 | NULL |
| 99966 | ROMA2 | 1 | 2022-06-14 | 1 | NULL |
| 99977 | ROMA2 | 1 | 2022-06-15 | 1 | NULL |
| 99938 | ROMA2 | 2 | 2022-06-11 | 1 | NULL |
| 99949 | ROMA2 | 2 | 2022-06-12 | 1 | NULL |
| 99951 | ROMA2 | 2 | 2022-06-13 | 1 | NULL |
| 99962 | ROMA2 | 2 | 2022-06-14 | 1 | NULL |
| 99973 | ROMA2 | 2 | 2022-06-15 | 1 | NULL |
and when the booking takes place, 'id_prenotazione' is entered for the booking id and the 'value' from 1 becomes 0.
now the problem is that if I filter from these two dates he occupies me all the 'sala' in that date range and does not stop at just 'sala' with a single 'table' if I change the type of query trying to select only one sala with a table by setting an order by id to have them loaded in order of sala and table eg. from 15-06-2020 to 17-06-2020 I have a reservation then I make another one from 15-06-2022 to 20-06-2022 he does not book me every day but only makes 18-19-20 to finish the 'hall'
the question is: how can I execute the correct query to insert the reservation_id in a date range that occupies only one place and not all of them?
i do this
$sql = "select * from risto_prenota where valore='1' AND id_prenotazione IS NULL and data between '$data_inizio' and '$data_fine' ORDER BY `risto_prenota`.`id` DESC";
$resultSet2 = mysqli_query($db, $sql);
while ($row = mysqli_fetch_array($resultSet2)) {
$sala = $row["sala"];
$tavolo=$row["tavolo"];}
and then this:
$sql = "select * from risto_prenota where valore='1' and data between '$data_inizio' and '$data_fine' order by id DESC";
$resultSet2 = mysqli_query($db, $sql);
while ($row = mysqli_fetch_array($resultSet2)) {
$data_prenota=$row["data"];
//echo $data_prenota;
//echo "</BR>";
$id_pren=$row["id"];
//echo $id_pren;
$query = "UPDATE risto_prenota SET valore = '0', id_prenotazione='$id_prenotazione' where id = '$id_pren' and sala='$sala' and tavolo='$tavolo' ";
if ($link->query($query) === TRUE) {
} else {
}
it doesn't work right if i make a reservation from 2022-06-11 to 2022-06-13 it becomes with code up:
| id | sala | tavolo | data | valore | id_prenotazione |
|---|---|---|---|---|---|
| 9993 | ROMA | 1 | 2022-06-11 | 0 | 111 |
| 9994 | ROMA | 1 | 2022-06-12 | 0 | 111 |
| 9995 | ROMA | 1 | 2022-06-13 | 0 | 111 |
| 9996 | ROMA | 1 | 2022-06-14 | 1 | NULL |
| 9997 | ROMA | 1 | 2022-06-15 | 1 | NULL |
| 99933 | ROMA2 | 1 | 2022-06-11 | 1 | NULL |
| 99944 | ROMA2 | 1 | 2022-06-12 | 1 | NULL |
| 99955 | ROMA2 | 1 | 2022-06-13 | 1 | NULL |
| 99966 | ROMA2 | 1 | 2022-06-14 | 1 | NULL |
| 99977 | ROMA2 | 1 | 2022-06-15 | 1 | NULL |
| 99938 | ROMA2 | 2 | 2022-06-11 | 1 | NULL |
| 99949 | ROMA2 | 2 | 2022-06-12 | 1 | NULL |
| 99951 | ROMA2 | 2 | 2022-06-13 | 1 | NULL |
| 99962 | ROMA2 | 2 | 2022-06-14 | 1 | NULL |
| 99973 | ROMA2 | 2 | 2022-06-15 | 1 | NULL |
then if i make a reservation from 2022-06-11 to 2022-06-15 it becomes:
| id | sala | tavolo | data | valore | id_prenotazione |
|---|---|---|---|---|---|
| 9993 | ROMA | 1 | 2022-06-11 | 0 | 111 |
| 9994 | ROMA | 1 | 2022-06-12 | 0 | 111 |
| 9995 | ROMA | 1 | 2022-06-13 | 0 | 111 |
| 9996 | ROMA | 1 | 2022-06-14 | 0 | 112 |
| 9997 | ROMA | 1 | 2022-06-15 | 0 | 112 |
| 99933 | ROMA2 | 1 | 2022-06-11 | 1 | NULL |
| 99944 | ROMA2 | 1 | 2022-06-12 | 1 | NULL |
| 99955 | ROMA2 | 1 | 2022-06-13 | 1 | NULL |
| 99966 | ROMA2 | 1 | 2022-06-14 | 1 | NULL |
| 99977 | ROMA2 | 1 | 2022-06-15 | 1 | NULL |
| 99938 | ROMA2 | 2 | 2022-06-11 | 1 | NULL |
| 99949 | ROMA2 | 2 | 2022-06-12 | 1 | NULL |
| 99951 | ROMA2 | 2 | 2022-06-13 | 1 | NULL |
| 99962 | ROMA2 | 2 | 2022-06-14 | 1 | NULL |
| 99973 | ROMA2 | 2 | 2022-06-15 | 1 | NULL |
skip days