Re: list of Months
| From: | Tom Rogers | Date: | Fri, 01 Oct 2004 04:16:54 +0000 |
| Subject: | Re: list of Months | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198374@lists.php.net to get a copy of this message | ||
Hi,
Friday, October 1, 2004, 6:16:46 AM, you wrote:
aan> Hi,
aan> to create a list of all months in drop-down menu I use this code:
aan> <?php
aan> $month_names = array(1=>'Jan', 'Feb', 'Mar',
aan> 'Apr', 'May', 'Jun', 'Jul',
aan> 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
?>>
aan> <select name="QuoteMonth">
aan> <option value=""></option>
aan> <?php
aan> for($i=1; $i<=12; $i++)
aan> {
aan> if(date('m') == $i) $selected_QuoteMonth = 'SELECTED';
aan> else $selected_QuoteMonth = '';
aan> echo "<option value=$i $selected_QuoteMonth> $i </option>";
aan> }
?>>
aan> </select>
aan> Is there any better way?
aan> Thanks for any help.
aan> Afan
Another way to skin this cat :
$month_names = array(
'Jan'=>'', 'Feb'=>'',
'Mar'=>'','Apr'=>'',
'May'=>'', 'Jun'=>'',
'Jul'=>'','Aug'=>'',
'Sep'=>'', 'Oct'=>'',
'Nov'=>'', 'Dec'=>'');
$month_names[date('M')] = ' selected';
echo '<select name="month">';
foreach($month_names as $month=>$selected){
echo '<option
value="'.$month.'"'.$selected.'>'.$month.'</option>';
}
echo '</select>';
--
regards,
Tom