dennismonsewicz Posted May 6, 2008 Share Posted May 6, 2008 I am wanting to have a select drop down list that is hard coded. But I would like for it to select the month that is current to the server. So when a user comes across the page the month that is selected in the list is the current month! Make sense? Any ideas? Quote Link to comment Share on other sites More sharing options...
blackcell Posted May 6, 2008 Share Posted May 6, 2008 I know this is the hard way to do this but here's the code. Let me know an easier way someone lol. <?php switch(date("m")){ case 01: $MONTH1 = "January"; $MONTH2 = "Feburary"; $MONTH3 = "March"; $MONTH4 = "April"; $MONTH5 = "May"; $MONTH6 = "June"; $MONTH7 = "July"; $MONTH8 = "August"; $MONTH9 = "September"; $MONTH10 = "October"; $MONTH11 = "November"; $MONTH12 = "December"; break; case 02: $MONTH2 = "January"; $MONTH1 = "Feburary"; $MONTH3 = "March"; $MONTH4 = "April"; $MONTH5 = "May"; $MONTH6 = "June"; $MONTH7 = "July"; $MONTH8 = "August"; $MONTH9 = "September"; $MONTH10 = "October"; $MONTH11 = "November"; $MONTH12 = "December"; break; case 03: $MONTH2 = "January"; $MONTH3 = "Feburary"; $MONTH1 = "March"; $MONTH4 = "April"; $MONTH5 = "May"; $MONTH6 = "June"; $MONTH7 = "July"; $MONTH8 = "August"; $MONTH9 = "September"; $MONTH10 = "October"; $MONTH11 = "November"; $MONTH12 = "December"; break; case 04: $MONTH2 = "January"; $MONTH3 = "Feburary"; $MONTH4 = "March"; $MONTH1 = "April"; $MONTH5 = "May"; $MONTH6 = "June"; $MONTH7 = "July"; $MONTH8 = "August"; $MONTH9 = "September"; $MONTH10 = "October"; $MONTH11 = "November"; $MONTH12 = "December"; break; case 05: $MONTH2 = "January"; $MONTH3 = "Feburary"; $MONTH4 = "March"; $MONTH5 = "April"; $MONTH1 = "May"; $MONTH6 = "June"; $MONTH7 = "July"; $MONTH8 = "August"; $MONTH9 = "September"; $MONTH10 = "October"; $MONTH11 = "November"; $MONTH12 = "December"; break; case 06: $MONTH2 = "January"; $MONTH3 = "Feburary"; $MONTH4 = "March"; $MONTH5 = "April"; $MONTH6 = "May"; $MONTH1 = "June"; $MONTH7 = "July"; $MONTH8 = "August"; $MONTH9 = "September"; $MONTH10 = "October"; $MONTH11 = "November"; $MONTH12 = "December"; break; case 07: $MONTH2 = "January"; $MONTH3 = "Feburary"; $MONTH4 = "March"; $MONTH5 = "April"; $MONTH6 = "May"; $MONTH7 = "June"; $MONTH1 = "July"; $MONTH8 = "August"; $MONTH9 = "September"; $MONTH10 = "October"; $MONTH11 = "November"; $MONTH12 = "December"; break; case 08: $MONTH2 = "January"; $MONTH3 = "Feburary"; $MONTH4 = "March"; $MONTH5 = "April"; $MONTH6 = "May"; $MONTH7 = "June"; $MONTH8 = "July"; $MONTH1 = "August"; $MONTH9 = "September"; $MONTH10 = "October"; $MONTH11 = "November"; $MONTH12 = "December"; break; case 09: $MONTH2 = "January"; $MONTH3 = "Feburary"; $MONTH4 = "March"; $MONTH5 = "April"; $MONTH6 = "May"; $MONTH7 = "June"; $MONTH8 = "July"; $MONTH9 = "August"; $MONTH1 = "September"; $MONTH10 = "October"; $MONTH11 = "November"; $MONTH12 = "December"; break; case 10: $MONTH2 = "January"; $MONTH3 = "Feburary"; $MONTH4 = "March"; $MONTH5 = "April"; $MONTH6 = "May"; $MONTH7 = "June"; $MONTH8 = "July"; $MONTH9 = "August"; $MONTH10 = "September"; $MONTH1 = "October"; $MONTH11 = "November"; $MONTH12 = "December"; break; case 11: $MONTH2 = "January"; $MONTH3 = "Feburary"; $MONTH4 = "March"; $MONTH5 = "April"; $MONTH6 = "May"; $MONTH7 = "June"; $MONTH8 = "July"; $MONTH9 = "August"; $MONTH10 = "September"; $MONTH11 = "October"; $MONTH1 = "November"; $MONTH12 = "December"; break; case 12: $MONTH2 = "January"; $MONTH3 = "Feburary"; $MONTH4 = "March"; $MONTH5 = "April"; $MONTH6 = "May"; $MONTH7 = "June"; $MONTH8 = "July"; $MONTH9 = "August"; $MONTH10 = "September"; $MONTH11 = "October"; $MONTH12 = "November"; $MONTH1 = "December"; break; } $select = " <select name='month'> <option value ='$MONTH1'>$MONTH1</option> <option value ='$MONTH2'>$MONTH2</option> <option value ='$MONTH3'>$MONTH3</option> <option value ='$MONTH4'>$MONTH4</option> <option value ='$MONTH5'>$MONTH5</option> <option value ='$MONTH6'>$MONTH6</option> <option value ='$MONTH7'>$MONTH7</option> <option value ='$MONTH8'>$MONTH8</option> <option value ='$MONTH9'>$MONTH9</option> <option value ='$MONTH10'>$MONTH10</option> <option value ='$MONTH11'>$MONTH11</option> <option value ='$MONTH12'>$MONTH12</option> </select> "; echo $select; ?> Quote Link to comment Share on other sites More sharing options...
QuietWhistler Posted May 6, 2008 Share Posted May 6, 2008 <?php $currentMonth = 2; //february integer value ?> <select name="month"> <?php $months = array( "January", "February", "March" ); //etc. for( $i = 0; $i < sizeof( $months ); $i++ ) { if( $currentMonth == ( $i + 1 ) { print( "<option selected>" . $months[ $i ] . "</option>" ); } else { print( "<option>" . $months[ $i ] . "</option>" ); } } ?> </select> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 6, 2008 Share Posted May 6, 2008 Or even just: <select name="month"> <?php $monthno = date('n'); for($x=1;$x<=12;$x++){ $month = date('F',strtotime($x.'/01/08')); $selected = ($monthno == $x)? ' selected="selected" ':''; echo '<option value="'.$month.'"'.$selected.'>'.$month.'</option>'; } ?> </select> Quote Link to comment Share on other sites More sharing options...
sanderphp Posted May 6, 2008 Share Posted May 6, 2008 <select name="datemonth" id="datemonth"> <option value="January" <?php if (date('F') == "January"){ echo "selected";} ?>>January</option> <option value="February" <?php if (date('F') == "February"){ echo "selected";} ?>>February</option> <option value="March" <?php if (date('F') == "March"){ echo "selected";} ?>>March</option> <option value="April" <?php if (date('F') == "April"){ echo "selected";} ?>>April</option> <option value="May" <?php if (date('F') == "May"){ echo "selected";} ?>>May</option> </select> Quote Link to comment Share on other sites More sharing options...
blackcell Posted May 7, 2008 Share Posted May 7, 2008 I like sander php the best 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.