Double March , no February in PHP date

Discussion in 'PHP' started by soggy, Jan 31, 2008.

  1. #1
    Greetings,

    For some reason the code below is producing (2) Marches and no February in the dropdown. Can some experts lend advice?

    Jan
    Mar
    Mar
    April
    May
    etc

    		<select name=month>
    		<?
    		for($m = '1'; $m <= '12'; $m++)
    		{
    			$MonthWord = date('F', mktime(0,0,0,$m,date(d),date(Y)));
    
    			if($m == date(n) || $m == $_POST[month])
    			{
    				echo "<option value=$m selected>$MonthWord</option>";	
    			}
    			else
    			{
    				echo "<option value=$m>$MonthWord</option>";	
    			}
    		}
    		?>
    		</select>
    
    		&nbsp;
    
    		<select name=day>
    		<?
    		for($d = '1'; $d <= '31'; $d++)
    		{
    			if($d == date(j) || $d == $_POST[day])
    			{
    				echo "<option value=$d selected>$d</option>";	
    			}
    			else
    			{
    				echo "<option value=$d>$d</option>";	
    			}
    		}
    		?>
    		</select>		
    
    		&nbsp;
    
    		<select name=year>
    		<?
    		for($y = '2005'; $y <= date(Y); $y++)
    		{
    			if($y == date(Y) || $y == $_POST[year])
    			{
    				echo "<option value=$y selected>$y</option>\n";	
    			}
    			else
    			{
    				echo "<option value=$y>$y</option>\n";	
    			}
    		}
    		?>
    		</select>
    Code (markup):
     
    soggy, Jan 31, 2008 IP
  2. rspenc29

    rspenc29 Peon

    Messages:
    256
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I would start by fixing all the missing quotes
     
    rspenc29, Jan 31, 2008 IP
  3. soggy

    soggy Active Member

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #3
    i am a newbie, can you point out which ones?
     
    soggy, Jan 31, 2008 IP
  4. LittleJonSupportSite

    LittleJonSupportSite Peon

    Messages:
    386
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well first off there is no Feb 29th or Feb 30th so that would not work from the 29th on in any month...

    try this instead:

    
    
    <?php
    $day=1;
    $year=date(Y);
    $year=2008;
    for($mon=1; $mon<=12; $mon++)
    {
    echo "<option>".date('F',mktime(0,0,0,$mon,$day,$year))."</option>\n";
    }
    ?>
    
    Code (markup):
     
    LittleJonSupportSite, Jan 31, 2008 IP
  5. soggy

    soggy Active Member

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #5
    $MonthWord = date('F', mktime(0,0,0,$m,1));

    This resolved it as well. thanks everyone for the help.
     
    soggy, Jan 31, 2008 IP
  6. LittleJonSupportSite

    LittleJonSupportSite Peon

    Messages:
    386
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It is very important to understand WHY that worked.

    I posted the code so you can learn form it with an explanation as to why yours failed.

    As you just saw sometimes you can be a little too dynamic.

    Have a great day.
     
    LittleJonSupportSite, Jan 31, 2008 IP
  7. soggy

    soggy Active Member

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #7
    agreed, thanks a bunch
     
    soggy, Jan 31, 2008 IP