#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Posts
    98
    Rep Power
    9

    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:

    PHP Code:
    for($m 1;$m <= 12$m++)
    {
    $month date("F"mktime(000$m1));
    echo 
    "<option value='$m'>$month</option>";
    }


    for (
    $x=(date('Y'mktime())); $x >= 1960$x--)
    {
     echo 
    "<option value='$x'>$x</option>";

    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.
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,301
    Rep Power
    7170
    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).
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Posts
    98
    Rep Power
    9
    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:

    PHP Code:
    <select name='month'>";

    $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]."";
    }
    echo "
    </select>";


IMN logo majestic logo threadwatch logo seochat tools logo