PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Mon May 22, 2006 2:56 am
I want to populate my listbox with months like this
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
how to do this?
any idea?
thanks much.
bdlang
Forum Contributor
Posts: 395 Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US
Post
by bdlang » Mon May 22, 2006 3:00 am
Store the month names in an array and loop over them with
foreach() to create the elements you want.
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Mon May 22, 2006 6:01 am
thanks much,
let me try
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Mon May 22, 2006 6:21 am
I thought you had a moth infestation for a moment there
opensme
Forum Newbie
Posts: 3 Joined: Mon May 22, 2006 8:25 am
Post
by opensme » Mon May 22, 2006 9:17 am
Code: Select all
<?php
echo '<select name="month">';
$months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct ', 'Nov', 'Dec');
foreach ($months as $month) {
// Set select box to current month
if (date("M") == $month) {
echo '<option value="'.$month.'" selected>'.$month.'</option>';
}
else {
echo '<option value="'.$month.'">'.$month.'</option>';
}
}
echo '</select>';
?>