Re: Months of the year

From: Date: Mon, 06 Jan 2003 10:44:18 +0000
Subject: Re: Months of the year
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-130382@lists.php.net to get a copy of this message
Another solution: $month_now = date("n"); echo "<select name=\"month\">\n"; for($i=$month_now, $j=0; $i<=($month_now+12); $i++,$j++) { echo "<option value=\"$i\""; if($i == $month_now) { echo " selected"; } echo ">" . date("F Y", mktime(0, 0, 0, $month_now+$j, 1, date("Y"))) . "</option>\n"; } echo "</select>\n"; This will start the month's dropdown on the month of the year through to the month of the following year, e.g. January 2003 to January 2004, February 2003 to February 2004, etc. James "David Freeman" <dfreeman@outbackqld.net.au> wrote in message news:006e01c2b56e$d559fe30$0b0a0a0a@skink... > > > How do I create a drop down list that automatically > > generates a list of months for the next 12 months upto and including > this month > > This would do it... > > <select name="st_month" style="width: 80px" class="forms"> > <?PHP > $curr_month = date("n", mktime()); > > for ($x = 1; $x <= 12; $x++) > { > $month_name = date("F", mktime(0, 0, 0, $x, 1, 2002)); > if ($x == $curr_month) > { > echo " <option value=\"$x\" > selected>$month_name</option>\n"; > } else { > echo " <option value=\"$x\">$month_name</option>\n"; > } > } > ?> > </select> > > >

« previous php.general (#130382) next »