title: Populate drop down form with months and year php
body: <p>I am trying to create two drop downs with HTML and PHP. The first is an auto submit that sends a month to a session variable:</p>
  
  <pre><code>&lt;form action="" method="post"&gt;
        &lt;select name="month" onchange="this.form.submit()"&gt;
          &lt;option value=""&gt;-- Select Month --&lt;/option&gt;
          &lt;?php $month = date('n'); // current month
           for ($x = 0; $x &lt; 12; $x++) { ?&gt;
            &lt;option value="&lt;?php echo date('m', mktime(0,0,0,$month + $x,1)); ?&gt;" 
            &lt;?php echo date('m', mktime(0,0,0,$month + $x,1)) == $_SESSION['month'] ? "selected='selected'":""; ?&gt; &gt;
            &lt;?php echo date('F Y', mktime(0,0,0,$month + $x,1)); ?&gt;
           &lt;?php } ?&gt;
        &lt;/select&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>This works great. But I then need a second drop down with the day name and number:</p>
  
  <pre><code>&lt;form action="" method="post"&gt;
        &lt;select name="day" onchange="this.form.submit()"&gt;
          &lt;option value=""&gt;-- Select Day --&lt;/option&gt;
          &lt;?php for ($i = $current_day; $i &lt; 31; $i++) { 
          $tmp_date = $_SESSION['year']."/".$_SESSION['month']."/".$i; 
                $weekday = date('D', strtotime($tmp_date));  { ?&gt;
          &lt;option value="&lt;?php echo $i; ?&gt;" &lt;?php echo $i == $_SESSION['day'] ? "selected='selected'":""; ?&gt; &gt;
          &lt;?php echo $weekday." ".$i; ?&gt;
       &lt;?php  } ?&gt;  
       &lt;?php } ?&gt;
          &lt;/option&gt;
          &lt;?php } ?&gt;
        &lt;/select&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>This uses a temp date with a session variable as '2014' which I set before. I need to remove the session year variable and get the first drop down to know which year the month selected is and then pass this to the temp date so that it populates the day name and number correctly for the next year (2015) if you choose January onwards. At the moment it only shows the day name and number from the current year (2014) in this case.</p>