months issue

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

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

months issue

Post by itsmani1 »

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 »

Store the month names in an array and loop over them with foreach() to create the elements you want.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

thanks much,
let me try
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

:lol: I thought you had a moth infestation for a moment there :lol:
opensme
Forum Newbie
Posts: 3
Joined: Mon May 22, 2006 8:25 am

Post by opensme »

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>';
?>
Post Reply