I need to consult the following id where the following is fulfilled:
Values entered by the user from 1 to 5 (people per room), and I have to obtain the id's of the hotels where it is true that there is a place, for example;
ROOM-1 : 2 PASSENGERS;
ROOM-2 : 3 PASSENGERS;
DATABASE:
CORRECT RESULT 1 =
FECHA:18/09/2018;
ID:HOTEL100001;
DOBLE:CUPO 1;
TRIPLE:CUPO 1;
CUADRUPLE:CUPO 1;
CORRECT RESULT 2 =
FECHA:18/09/2018;
ID:HOTEL100002;
DOBLE:CUPO 0;
TRIPLE:CUPO 4;
CUADRUPLE:CUPO 0;
INCORRECT RESULT 3 =
FECHA:18/09/2018;
ID:HOTEL100003;
DOBLE:CUPO 0;
TRIPLE:CUPO 1;
CUADRUPLE:CUPO 0;
Thanks for the help
MySQL query
$ mysqli = new mysqli ("localhost", "root", "pass", "db"); / * verify connection / if (mysqli_connect_errno ()) { printf ("Connect failed:% s \ n", mysqli_connect_error ()); exit (); } / create a prepared statement * /
$cupo_habitacion1=1;
$personashabitacion1=2;
$cupo_habitacion2=1;
$personashabitacion2=2;
if ($stmt = $mysqli->prepare("
SELECT id_hotel from cupo_tarifa_hoteles WHERE capacidad_habitacion>=? AND cupo_hotel >=?
INTERSECT
SELECT id_hotel from cupo_tarifa_hoteles WHERE capacidad_habitacion >=? AND cupo_hotel >=? ")) {
mysqli_stmt_bind_param($stmt, "ssss", $personashabitacion1,$habitacion1,$personashabitacion2,$habitacion2);
/* ejecutar la consulta */
mysqli_stmt_execute($stmt);
/* ligar variables de resultado */
mysqli_stmt_bind_result($stmt, $id_hotel);
/* obtener valor */
while ( $stmt->fetch() ) {
echo $id_hotel;
}
/* cerrar sentencia */
$stmt->close();
}
/* cerrar conexión */
$mysqli->close();