PDA

View Full Version : [php] Month/Year Select Box



mobilebadboy
09-09-2009, 05:11 PM
I've been trying to wrap my head around this for a long time now. In my head I know the theory of what needs to be done but every time I sit and try to type out the code, my mind goes blank.

I have a form with a Month/Year format (combined) and the first date is always the current month/year followed by 17 future months + incremented year when needed, ie:



<option value="9/1/2009">September 2009</option>
<option value="10/1/2009">October 2009</option>
<option value="11/1/2009">November 2009</option>
..... .....
<option value="12/1/2010">December 2010</option>
<option value="1/1/2011">January 2011</option>
<option value="2/1/2011">February 2011</option>

Currently this is updated manually and I often forget to do it, which is why I'd like to finally get this straight and forget it. The year rollover part, 09 > 10 > 11, etc, is one of my major hangups (another thing I can imagine in my head, but not get in to code).

I've searched and searched, everything that I have found is separated in to multiple select menus.

Chris
09-10-2009, 11:20 AM
MAybe use a multidimensional array populated automatically then read from?

Chris
09-10-2009, 11:27 AM
... or easier... use php to get the number of the current month, and current year.



for($i=0;$i<18;$i++){

echo $month."/1/".$year;

if(($month % 12) == 0){
$year++;
$month=0;
}

$month++;

)

mobilebadboy
09-10-2009, 01:16 PM
Awesome, thanks Chris. I was in that area, but still way off, especially on that if operator.