note 19207 deleted from function.getdate by victor

From: Date: Sat, 24 Aug 2002 16:11:31 +0000
Subject: note 19207 deleted from function.getdate by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-35536@lists.php.net to get a copy of this message
Here is my version of the listbox of months. You can enter the starting month and a month to set as selected: <? function monthList($start="1", $selected="") { $totalMonths = 12; $start = (int) $start; $selected = (int) $selected; if ( $start < 1 ) { $start = 1; } $options = ""; for( $i=$start; $i<=$totalMonths; $i++) { if ( $i < 10 ) { $month = "0$i"; } else { $month = "$i"; } if ( $i == $selected ) { $options .= "<option selected value=\"$i\">$month</option>"; } else { $options .= "<option value=\"$i\">$month</option>"; } } $list = "<select name=\"month\">$options</select>"; return $list; } #### test the function echo monthList(); ##(defaults) start=Jan,selected=none echo "<br><br>"; echo monthList( date("m"),5 ); ##start=currentmonth,selected=May echo "<br><br>"; echo monthList( 3, 7 ); ##start=March,selected=July ?> You can even alter this method to do days and years. I have used this many times (with slight modifications). Hope this helps! Nicole Amashta www.aeontrek.com P.S. Sorry if my code looks funny. The format is out of my control. I usually have neat code, but it appears funny here.

« previous php.notes (#35536) next »