Re: Month

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dan Shirah wrote:
Greetings,

I have the following code which populates a dropdown box so a user can
select a month.  They see the month name and the SELECTED value is the
corresponding numeric value 1-12 for the month.   However, the selected
value for January would be 1. I need the selected value fro January to be
01.  How would I accomplish this?

<select name="month">
   <?PHP
    for ($m=1;$m<=12;$m++)
    {
     $months=date('M', mktime(0, 0, 0, $m, 1));
     if ($m == $_POST['month'])
      echo "<option value=\"{$m}\" SELECTED>{$months}</option>";
     else
      echo "<option value=\"$m\">$months</option>";
    }
   ?>
</select>

Probably a number of options..
check functions... str_pad(), sprintf()
Or you could just have an array...
$months = array('01'=>'January','02'=>'February', ...)
foreach($months as $k => $v) {
   echo "<option value=$k>$v</option>\n";
}
(Not usually recommended, but the name/values of months do not change often...)

-B

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux