cavey5 Posted June 29, 2007 Share Posted June 29, 2007 I have to populate a select box based on the date, so say between June 15th, 2007 and July 14th, 2007 it would echo <select> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> and between July 15th, 2007 and August 14th, 2007 it would echo <select> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> etc... what is the proper way to do this? I tried creating a date variable with $date = date(ymd); and then did an if statement like if (($date >= 070516) AND ($date <= 070715)) { echo "..."; } elseif if (($date >= 070716) AND ($date <= 070915)) { echo "..."; } else { ... } but it always defaults to the last else... what am I doing wrong? It has to be a logical error, right? Link to comment https://forums.phpfreaks.com/topic/57660-quick-conditionals-question/ Share on other sites More sharing options...
bluebyyou Posted June 29, 2007 Share Posted June 29, 2007 you dont need the second if after your elseif so.. if (($date >= 070516) AND ($date <= 070715)) { echo "..."; } elseif (($date >= 070716) AND ($date <= 070915)) { echo "..."; } else { ... } Link to comment https://forums.phpfreaks.com/topic/57660-quick-conditionals-question/#findComment-285502 Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 Well first what is $date? Your system looks like it is not very strong because your leading 0 is insignificant Also ifs are more in the fashion of if($param1 = $paramanswer && $parm2 = $parmanswer2) Join with the operator && in your case: if ($date >= 070516 && $date <= 070715) Link to comment https://forums.phpfreaks.com/topic/57660-quick-conditionals-question/#findComment-285504 Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 still shouldn't matter it should pick up case1 or 2 if it is valid Link to comment https://forums.phpfreaks.com/topic/57660-quick-conditionals-question/#findComment-285505 Share on other sites More sharing options...
corbin Posted June 29, 2007 Share Posted June 29, 2007 $min = strtotime("June 15, 2007"); //makes the unix timestamp of June 15, 2007 0:00 $max = strtotime("July 15, 2007"); if($min < time() && $max > time()) { //time is between the 2 dates } That's how I would do it. Link to comment https://forums.phpfreaks.com/topic/57660-quick-conditionals-question/#findComment-285508 Share on other sites More sharing options...
cavey5 Posted June 29, 2007 Author Share Posted June 29, 2007 Got it working, thanks... the logical error was the date(ymd); function which displays a two digit year with a leading zero, which has something do with base 8 and gets all screwy. I made is date(Ymd); which makes it 2007 and it works fine... Link to comment https://forums.phpfreaks.com/topic/57660-quick-conditionals-question/#findComment-285526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.