October 2nd, 2012, 07:19 PM
Making a drop down field for months and years
I need to create two form fields using PHP. One to populate a drop down field for the months of the year and one showing the current year and going back to 1960. I was using these but when I moved to a new hosting company that had the latest PHP it gave me a STRICT notice saying that I should be using time() instead of mktime(). Here's what I was using:
Can these be modified using the time() function? I tried changing the mktime() on the month list to time() but it gave me 12 Octobers.
for($m = 1;$m <= 12; $m++)
$month = date("F", mktime(0, 0, 0, $m, 1));
echo "<option value='$m'>$month</option>";
for ($x=(date('Y', mktime())); $x >= 1960; $x--)
echo "<option value='$x'>$x</option>";
October 2nd, 2012, 08:29 PM
Only change the second one. However, since "now" is the default argument for the date function, you can actually remove the second one completely (along with the comma and parenthesis of course).
October 2nd, 2012, 09:06 PM
Thanks for the help. I was able to get the one for the years going but not the months. So I went the long way around and made a month array:
$months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
for ($x=1; $x <= count($months); $x++)
echo "<option value='$x'>".$months[$x-1]."";