kirk112 Posted February 4, 2009 Share Posted February 4, 2009 Hi Can't seem to get my head around how to achieve this I need to be able to switch between a restaurant menu based on the date. Currently they are on menu one which is active from the 3rd Feb to 16th Feb and then changes to menu two on the 16th Feb to 2nd March and back to menu one on the 3rd and so on. Is they any way I can achieve this with out hard coding all possible dates for the next 3 years? Hope the above makes sense Thanks for your help! Quote Link to comment Share on other sites More sharing options...
aschk Posted February 4, 2009 Share Posted February 4, 2009 Yes, store the information in a db, and every time the menu page (item, class, whatever) is called then you do a lookup on the date range in the db, and pull the relevant menu number ... Quote Link to comment Share on other sites More sharing options...
kirk112 Posted February 4, 2009 Author Share Posted February 4, 2009 Hi aschk Thanks for your reply, was hoping that there might be a logical way of performing the calculation i.e. 64 days has past from point A so that means display menu 1 (know that this is way off <--) Not looking for someone to provide the full script just a bit of logic of how this can be done Thanks agains!! Quote Link to comment Share on other sites More sharing options...
gevans Posted February 4, 2009 Share Posted February 4, 2009 A bit of a random way for it to work... I'll try and explain it, and if you don't udnerstnad I'll give you some code as I don't have it fully working in my head yet. get the integer value for the start month (so for feburary - 2) check todays month and day, it its not past the third take 1 away from the month so (april 2nd: month int - 3 (march)) if the current month subtract the start month is an odd number display menu 2, if its an even number display menu 1 if the year has change you'll have to add 12 to the month int Hope some of that makes sense, I may have amde it sound more complicated tahn it actually is... Quote Link to comment Share on other sites More sharing options...
kirk112 Posted February 4, 2009 Author Share Posted February 4, 2009 ??? ??? ??? ??? Kind of understand could be useful if you could supply some code Just a bit more information not sure if you think it always changes on the 3rd (or if I have misunderstood what you have put) 3rd - 16th Feb Menu 1 17th - 2nd March Menu 2 3rd March - 16th March Menu 1 17th March -30th March Menu 2 31st March - 13th March Menu 1 Thanks for your help - the more I try to work this out the more confused I get! Quote Link to comment Share on other sites More sharing options...
gevans Posted February 4, 2009 Share Posted February 4, 2009 Ahhh, always for two weeks, well that could make it easier again, sort of... give me a few minutes and ill see what I can come up with. Quote Link to comment Share on other sites More sharing options...
gevans Posted February 4, 2009 Share Posted February 4, 2009 I think I've got something..... Don't know if it's the best solution, but it's a solution <?php function menu() { $start_stamp = strtotime('2009-02-03');//Start date YYYY-MM-DD $two_weeks = (60*60*24*14);//timestamp equivalent of two weeks $diff = time()-$start_stamp;//difference between today and start date $weeks = floor($diff/$two_weeks);//number of weeks since start date (rounded down) if($weeks%2) {//if odd return "menu two"; } else {//if even return "menu one"; } } echo menu(); ?> Quote Link to comment 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.