Jump to content

help with query, checking for double booking.


exploo

Recommended Posts

So. I'm making a booking system.
It's about booking of locals.
And I want to have a query to use, just to check if there is any double bookings.

This is how the table with all the booking look.
[pre]+---------------------+---------------------+-------+
| starttime          | endtime            | local |
+---------------------+---------------------+-------+
| 2006-11-05 11:00:00 | 2006-11-05 12:00:00 |    1 |
| 2006-11-12 11:00:00 | 2006-11-12 12:00:00 |    2 |
| 2006-11-19 11:00:00 | 2006-11-19 12:00:00 |    1 |
| 2006-11-22 11:00:00 | 2006-11-22 12:30:00 |    2 |
| 2006-11-22 11:00:00 | 2006-11-22 12:30:00 |    1 |
+---------------------+---------------------+-------+[/pre]

This is the query i use in my PHP function, when the data is insertet. to check if there's local is used between $startime2 and $endtime2.
[pre]SELECT 1 FROM bookings WHERE endtime>$startime2 AND starttime<$endtime2 AND local=$local;[/pre]
If a row is rerurned i know the local is busy and won't enter the data into the table.


But I also want a query for checking if a double booking somehow have happend, and is in the table.
In other words I would like to check the table against itself.

Can't really figure out how to do this.

I'm thankful for every help :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.