Jump to content

Archived

This topic is now archived and is closed to further replies.

9999

Pulldown problem

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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.