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
https://forums.phpfreaks.com/topic/19302-pulldown-problem/
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
https://forums.phpfreaks.com/topic/19302-pulldown-problem/#findComment-83723
Share on other sites

Archived

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

×
×
  • 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.