Jump to content

Recommended Posts

Hi all,

 

I have a booking system which stores different prices for different time periods.

 

For instance:

 

2011-06-10    -    2011-06-20  = £100

2011-06-21    -    2011-06-30  = £200

 

I have a date range:  ( 2011-06-15  -  2011-06-25  ), which is half way between both of the above ranges.

 

What is the best way to query the database to get a total price for the supplied date range.

 

I was using:

 

SELECT id,start,end,rate,request FROM `pricebands` 
WHERE ((start >= '$start' AND start <= '$end') 
OR (end >= '$start' AND end <= '$end')
OR (start >= '$start' AND end <= '$end')
OR (start <= '$start' AND end >= '$end'))
GROUP BY request ORDER BY request ASC

 

but obviously grouping by 'request' (1 or 0) will not return the prices correctly. I thought about looping through each day and returning it's price then calculating but this seems excessive.

 

Any ideas?

 

Link to comment
https://forums.phpfreaks.com/topic/236837-return-total-price-for-date-range/
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.