comparing months not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • whatchamakeofit

    comparing months not working

    hi. i have the following code:

    $now=getdate();
    $currMonth = $now["month"];
    $currYear = $now["year"];
    $currDay = $now["mday"];
    for($i=1; $i<=12; $i++){
    $month = date("F",mktime (0, 0, 0, $i));
    if ($month == $currMonth)
    echo "<option value='".$month ."' selected='selec ted'>".$month." </
    option>";
    else
    echo "<option value='".$month ."'>".$month ."</option>";
    }

    all i want to do is dynamically output a selection box containing all
    the months of the year, and have the selection default to the current
    month. however, i'm not sure why it's not working. please help.
    thanks
  • Olaf Schinkel

    #2
    Re: comparing months not working

    whatchamakeofit schrieb:
    hi. i have the following code:
    >
    $now=getdate();
    $currMonth = $now["month"];
    $currYear = $now["year"];
    $currDay = $now["mday"];
    for($i=1; $i<=12; $i++){
    $month = date("F",mktime (0, 0, 0, $i));
    if ($month == $currMonth)
    echo "<option value='".$month ."' selected='selec ted'>".$month." </
    option>";
    else
    echo "<option value='".$month ."'>".$month ."</option>";
    }
    >
    all i want to do is dynamically output a selection box containing all
    the months of the year, and have the selection default to the current
    month. however, i'm not sure why it's not working. please help.
    thanks
    Why not using $now['mon']; ? 1-12
    And later if ($i == $now['mon']) ?

    Comment

    • whatchamakeofit

      #3
      Re: comparing months not working

      thx, that works!

      but, i'm still wondering, why wouldn't my previous code work?

      On Jul 12, 10:14 am, Olaf Schinkel <tr...@schinkel .tvwrote:
      whatchamakeofit schrieb:
      >
      hi. i have the following code:
      >
      $now=getdate();
      $currMonth = $now["month"];
      $currYear = $now["year"];
      $currDay = $now["mday"];
      for($i=1; $i<=12; $i++){
      $month = date("F",mktime (0, 0, 0, $i));
      if ($month == $currMonth)
      echo "<option value='".$month ."' selected='selec ted'>".$month." </
      option>";
      else
      echo "<option value='".$month ."'>".$month ."</option>";
      }
      >
      all i want to do is dynamically output a selection box containing all
      the months of the year, and have the selection default to the current
      month. however, i'm not sure why it's not working. please help.
      thanks
      >
      Why not using $now['mon']; ? 1-12
      And later if ($i == $now['mon']) ?

      Comment

      • Chuck Anderson

        #4
        Re: comparing months not working

        whatchamakeofit wrote:
        hi. i have the following code:
        >
        $now=getdate();
        $currMonth = $now["month"];
        $currYear = $now["year"];
        $currDay = $now["mday"];
        for($i=1; $i<=12; $i++){
        $month = date("F",mktime (0, 0, 0, $i));
        if ($month == $currMonth)
        echo "<option value='".$month ."' selected='selec ted'>".$month." </
        option>";
        else
        echo "<option value='".$month ."'>".$month ."</option>";
        }
        >
        all i want to do is dynamically output a selection box containing all
        the months of the year, and have the selection default to the current
        month. however, i'm not sure why it's not working. please help.
        thanks
        >
        Works for me.

        --
        *************** **************
        Chuck Anderson • Boulder, CO

        Nothing he's got he really needs
        Twenty first century schizoid man.
        *************** *************** *****

        Comment

        Working...