RE: [PHP] list of Months
| From: | Graham Cossey | Date: | Thu, 30 Sep 2004 21:49:28 +0000 |
| Subject: | RE: [PHP] list of Months | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198352@lists.php.net to get a copy of this message | ||
What you have is basically what I do, but the current month check could be
tidied up and display the month name seeing as you have the array:
$selected_QuoteMonth = (date('m')==$i)?'SELECTED':'';
echo "<option value=$i $selected_QuoteMonth> $month_names[$i] </option>";
** CODE IS UNTESTED **
I'm sure if there is a better way then someone here will let u know.
HTH
Graham
-----Original Message-----
From: afan@afan.net [mailto:afan@afan.net]
Sent: 30 September 2004 21:17
To: php-general@lists.php.net
Subject: [PHP] list of Months
Hi,
to create a list of all months in drop-down menu I use this code:
<?php
$month_names = array(1=>'Jan', 'Feb', 'Mar', 'Apr',
'May', 'Jun', 'Jul',
'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
?>
<select name="QuoteMonth">
<option value=""></option>
<?php
for($i=1; $i<=12; $i++)
{
if(date('m') == $i) $selected_QuoteMonth = 'SELECTED';
else $selected_QuoteMonth = '';
echo "<option value=$i $selected_QuoteMonth> $i </option>";
}
?>
</select>
Is there any better way?
Thanks for any help.
Afan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php