Jump to content

Bit of advice on best way to find available days


dc_jt

Recommended Posts

Hi

 

Ive got a database which contains holidays (days of which a store will not be open). E.g. Christmas Day (2008-12-25 00:00:00), Boxing Day ((2008-12-26 00:00:00) etc.

 

What I want to do is look at the next 5 days and if there is a holiday within the next 5 days then dont show this day else show it (in a radio button)

 

Therefore Ive got the following to get the next 5 days but whats the best way to remove the holidays?:

 

$dates = array();
for ($i=0;$i<5;$i++)
$dates[] = date('Y-m-d 00:00:00',strtotime('+' . $i . ' days'));

 

Not sure whether I should query the database for the holidays that match the next 5 days or whether to loop through the next 5 days and see if there are any holidays within these 5 days or what?

 

If you could tell me the best way, preferably with an example that would be great.

 

Thanks

Link to comment
Share on other sites

I have a lot of questions about what you're asking for, not to mention the structure of your database.  For example, you imply you used a DATETIME column when you really only need a DATE column.  This adds complexity, but basically, you can do a simple query like:

 

SELECT thedate FROM holidays WHERE thedate >= CURDATE() AND thedate 

 

If that result set returns any rows, read it into an array.  From there you'll have to figure out the format of the array, so that you match your php dates.    As you loop through, you'll attempt to find the date in your array, and if you match, then don't render your button.

 

One question that comes to mind is -- do you need 5 buttons regardless if the week has a holiday, or do you only show 4 in that case?  Your code may need to be altered from a for loop to a repeat unil in that case.

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.