Jump to content


Photo

Pulldown problem


  • Please log in to reply
2 replies to this topic

#1 9999

9999
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 31 August 2006 - 10:40 PM

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?

<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>


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 31 August 2006 - 10:53 PM

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

<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>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 9999

9999
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 31 August 2006 - 11:01 PM

Thanks a million.  Seems to work perfectly.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users