ShoeLace1291 Posted December 4, 2007 Share Posted December 4, 2007 I need a select dropdown menu that lists the name and number of the current month, the next month, and the previous month. It would have to look something like this: <select name='month'> <option value='1'>January</option> <option selected value='12'>December</option> <option value='11'>November</option> </select> This would change every month. For example, next month, January, would list February as the first month, January as the selected month, and December as the previous month. I have no idea how I would do something like this. Quote Link to comment https://forums.phpfreaks.com/topic/80164-date-select-menu/ Share on other sites More sharing options...
revraz Posted December 4, 2007 Share Posted December 4, 2007 Use strtotime to add and subtract months http://us.php.net/strtotime Quote Link to comment https://forums.phpfreaks.com/topic/80164-date-select-menu/#findComment-406301 Share on other sites More sharing options...
PHP_PhREEEk Posted December 4, 2007 Share Posted December 4, 2007 <?php echo '<select name="month"> '; for ( $x = -1 ; $x < 2 ; $x++ ) { $selected[0] = ' selected'; $month = get_month($x); echo ' <option value="' . $month[0] . '"' . $selected[$x] . '>' . $month[1] . '</option> '; } echo '</select>'; function get_month($offset) { return explode(" ", date("n F", mktime( 0, 0, 0, date("n")+$offset, 1, date("Y") )) ); } ?> /* HTML Source <select name="month"> <option value="11">November</option> <option value="12" selected>December</option> <option value="1">January</option> </select> */ PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/80164-date-select-menu/#findComment-406318 Share on other sites More sharing options...
mr_mind Posted December 4, 2007 Share Posted December 4, 2007 This will set the time using mktime(); and then print the time; if($_POST['submit']) { $month = $month = date("M", mktime(0,0,0,$_POST['month'],0,0,0)); print 'Month is: ' . $month; } else { print '<form action=' . $_SERVER['PHP_SELF'] . ' method=post>'; print '<select name=month>'; print '<option value=1>January</option>'; print '<option value=2>Febuary</option>'; print '<option value=3>March</option>'; print '<option value=4>April</option>'; print '<option value=5>May</option>'; print '<option value=6>June</option>'; print '<option value=7>July</option>'; print '<option value=8>August</option>'; print '<option value=9>September</option>'; print '<option value=10>October</option>'; print '<option value=11>November</option>'; print '<option value=12>December</option>'; print '</select>'; print '<input type=submit name=submit value=Submit />'; print '</form>'; } Quote Link to comment https://forums.phpfreaks.com/topic/80164-date-select-menu/#findComment-406329 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.