Jump to content

current month select option help


Recommended Posts

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;
?>

Link to comment
Share on other sites

<?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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

<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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.