jeudi 29 janvier 2015

How can I check if time period is already exist or between a specific period in database?

I have this query in my php. What i need to do is. i have example.


8:30 am to 10:00 am. so i want this time start and time end to be checked if it already exist in the database or it is between a time period.



input: 8:30 am to 10:00 am == database: 8:30 am to 10:am. -> already exist


input: 8:30 am to 11:30 am == database: 8:30 am to 10:am. -> already exist between


input: 9:30 am to 11:30 am == database: 8:30 am to 10:am. -> already exist between


input: 7:00 am to 11:30 am == database: 8:30 am to 10:am. -> already exist between


input: 7:00 am to 10:00 am == database: 8:30 am to 10:am. -> already exist between


input: 7:00 am to 9:30 am == database: 8:30 am to 10:am. -> already exist between



the code below works except that if the time start or time end is between the existing periods.. it still continues and doesn't tell me that it is already existing in between a period. i don't know what im lacking. thanks!



$Query = mysqli_query($Connection->con(),"SELECT
*
FROM room_schedules
INNER JOIN rooms
ON room_schedules.Room_ID = rooms.Room_ID
WHERE ((('" . htmlspecialchars($_POST['starts']) . "'
BETWEEN room_schedules.Starts
AND room_schedules.Ends)
AND ('" . htmlspecialchars($_POST['ends']) . "'
BETWEEN room_schedules.Starts
AND room_schedules.Ends))
OR ((room_schedules.Starts
BETWEEN '" . htmlspecialchars($_POST['starts']) . "'
AND '" . htmlspecialchars($_POST['ends']) . "')
AND (room_schedules.Ends
BETWEEN '" . htmlspecialchars($_POST['starts']) . "'
AND '" . htmlspecialchars($_POST['ends']) . "'))))




Aucun commentaire:

Enregistrer un commentaire