note 19207 added to function.getdate
| From: | NicoleAmashta at aeontrek dot com | Date: | Tue, 19 Feb 2002 20:38:20 +0000 |
| Subject: | note 19207 added to function.getdate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-26807@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.
--
http://www.php.net/manual/en/function.getdate.php
http://master.php.net/manage/user-notes.php?action=edit+19207
http://master.php.net/manage/user-notes.php?action=delete+19207
http://master.php.net/manage/user-notes.php?action=reject+19207