Jump to content

Pulldown problem


9999

Recommended Posts

This is a pulldown that automatically selects the current date. Today is August 31 and I noticed that in the pulldown, all the months that don't have 31 days are replaced with the ones that do. Any suggestions?

[code]<form action="index.php?" method="GET">

<select name="month">
<?php
for ($m = 1; $m <= 12; $m++)
{
      $date = mktime(0, 0, 0, $m);

      echo '<option value="'. date('F', $date) .'"'. ($m == date('n') ? ' selected="selected"' : '') .'>'. date('F', $date) .'</option>'. "\n";
}

?>
</select>

<select name="day">
<?php
for ($d = 1; $d <= 31; $d++)
{
    echo '<option value="'. $d .'"'. ($d == date('j') ? ' selected="selected"' : '') .'>'. $d .'</option>'. "\n";
}
?>
</select>

<input type="submit" name="Day Search" value="Day Search"/>

</form>[/code]
Link to comment
Share on other sites

That's because the date arithmetic takes 31st September and translates to 1st October.

It only happens when its the 31st (except for Feb) and you take the current day as default.

Try

[code]<select name="month">
<?php
for ($m = 1; $m <= 12; $m++)
{
      $date = mktime(0, 0, 0, $m, 1);

      echo '<option value="'. date('F', $date) .'"'. ($m == date('n') ? ' selected="selected"' : '') .'>'. date('F', $date) .'</option>'. "\n";
}

?>
</select> [/code]
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.