9999 Posted August 31, 2006 Share Posted August 31, 2006 This is a pulldown that automatically selects the current date. Today is August 31 and I noticed that in the pulldown, all the months that don't have 31 days are replaced with the ones that do. Any suggestions?[code]<form action="index.php?" method="GET"> <select name="month"> <?php for ($m = 1; $m <= 12; $m++) { $date = mktime(0, 0, 0, $m); echo '<option value="'. date('F', $date) .'"'. ($m == date('n') ? ' selected="selected"' : '') .'>'. date('F', $date) .'</option>'. "\n"; } ?> </select> <select name="day"> <?php for ($d = 1; $d <= 31; $d++) { echo '<option value="'. $d .'"'. ($d == date('j') ? ' selected="selected"' : '') .'>'. $d .'</option>'. "\n"; } ?> </select> <input type="submit" name="Day Search" value="Day Search"/> </form>[/code] Quote Link to comment Share on other sites More sharing options...
Barand Posted August 31, 2006 Share Posted August 31, 2006 That's because the date arithmetic takes 31st September and translates to 1st October.It only happens when its the 31st (except for Feb) and you take the current day as default.Try[code]<select name="month"> <?php for ($m = 1; $m <= 12; $m++) { $date = mktime(0, 0, 0, $m, 1); echo '<option value="'. date('F', $date) .'"'. ($m == date('n') ? ' selected="selected"' : '') .'>'. date('F', $date) .'</option>'. "\n"; } ?> </select> [/code] Quote Link to comment Share on other sites More sharing options...
9999 Posted August 31, 2006 Author Share Posted August 31, 2006 Thanks a million. Seems to work perfectly. 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.