dc_jt Posted February 4, 2008 Share Posted February 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/89333-bit-of-advice-on-best-way-to-find-available-days/ Share on other sites More sharing options...
gizmola Posted February 4, 2008 Share Posted February 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/89333-bit-of-advice-on-best-way-to-find-available-days/#findComment-457457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.