Jump to content

Recommended Posts

I am trying to create a bookings system for a hotel...

 

Would you create a field for every possible date.. therefore having a table with 365 fields for 2011?... then if it was booked have a bookingId that would join to another table with that booking data?

 

regards J

Link to comment
https://forums.phpfreaks.com/topic/232642-createing-a-bookings-system/
Share on other sites

Hi

 

Firstly, set up a table with 1 column 10 rows, with values from 0 to 9. In this case call it integers and the column name of i.

 

Then if you do the following you can select a range of numbers (joining the table against itself repeatedly). This gives you every number from 0 to 999, and the HAVING clause reduces it to 0 to 365.

 

SELECT a.i *100 + b.i *10 + c.i AS SomeNumber
FROM integers a, integers b, integers c
HAVING SomeNumber <=365

 

You can then add that number of days to a start date to get a range of dates. For example:-

 

SELECT DATE_SUB( '2011-01-01', INTERVAL a.SomeNumber DAY )
FROM (SELECT a.i *100 + b.i *10 + c.i AS SomeNumber
FROM integers a, integers b, integers c
HAVING SomeNumber <=365)a

 

All the best

 

Keith

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.