I'm trying to code a system that let's user book items. Items can't be booked twice. So if an item is unavailable i would like to know that by using SQL.
I've got a database with the following fields id,item, start (datetime), end (datetime)
A user will try to book an item from "01-01-2016 09:00" till "01-01-2016-22:00". But there is already a row where start is "01-01-2016 11:00" and end is "01-01-2016 16:00". So.. The item isn't available.
How can i do that in SQL?
Now i am using this:
SELECT * FROM `items` WHERE (`start` between '$start' and '$end') AND (`item` = $id)
Then i look if the number of rows is higher then 0. If so, the item is unavailable. This works.. but not when the start time is BEFORE the new start time.
I'm hoping that my explanation is clear... Having a hard time dealing with this issue because i can't get the facts straight.