PHP - Can't get my head around this!

Hitman
Soldato
Joined
25 Feb 2004
Posts
2,837
Hi,

I'm trying to set up a booking system and can't quite get my head around this. The bookings table looks like thus:

Code:
id | arrival | departure

'Arrival' and 'Departure' are in the format YYYY-MM-DD (2010-01-15 for example).

It should only allow one booking in a given period. So the table may look like this:

Code:
1 | 2010-01-15 | 2010-01-20
2 | 2010-01-21 | 2010-01-22
3 | 2010-01-24 | 2010-02-01

I need to run a check past the table to see if a slot is available or not, so if a client were to try and book 2010-01-16 until 2010-01-25, it would say no.

I've tried toying around with unix timestamp (I figured that may be an easier route to take?) but haven't had much luck.

Any ideas how this could be tackled?

Cheers
 
Hi,

I'm trying to set up a booking system and can't quite get my head around this. The bookings table looks like thus:

Code:
id | arrival | departure

'Arrival' and 'Departure' are in the format YYYY-MM-DD (2010-01-15 for example).

It should only allow one booking in a given period. So the table may look like this:

Code:
1 | 2010-01-15 | 2010-01-20
2 | 2010-01-21 | 2010-01-22
3 | 2010-01-24 | 2010-02-01

I need to run a check past the table to see if a slot is available or not, so if a client were to try and book 2010-01-16 until 2010-01-25, it would say no.

I've tried toying around with unix timestamp (I figured that may be an easier route to take?) but haven't had much luck.

Any ideas how this could be tackled?

Cheers

Just include it in a table query with a 'when' argument, then if any are returned the place is booked
 
Think I've got it working :)

Code:
SELECT * FROM table WHERE departure BETWEEN 'unix-ts-arrive' AND 'unix-ts-depart'

If it returns a row then it's not available to book.
 
Back
Top Bottom