470,596 Members | 1,450 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

comparing months not working

hi. i have the following code:

$now=getdate();
$currMonth = $now["month"];
$currYear = $now["year"];
$currDay = $now["mday"];
for($i=1; $i<=12; $i++){
$month = date("F",mktime(0, 0, 0, $i));
if ($month == $currMonth)
echo "<option value='".$month."' selected='selected'>".$month."</
option>";
else
echo "<option value='".$month."'>".$month."</option>";
}

all i want to do is dynamically output a selection box containing all
the months of the year, and have the selection default to the current
month. however, i'm not sure why it's not working. please help.
thanks
Jul 12 '08 #1
3 1168
whatchamakeofit schrieb:
hi. i have the following code:

$now=getdate();
$currMonth = $now["month"];
$currYear = $now["year"];
$currDay = $now["mday"];
for($i=1; $i<=12; $i++){
$month = date("F",mktime(0, 0, 0, $i));
if ($month == $currMonth)
echo "<option value='".$month."' selected='selected'>".$month."</
option>";
else
echo "<option value='".$month."'>".$month."</option>";
}

all i want to do is dynamically output a selection box containing all
the months of the year, and have the selection default to the current
month. however, i'm not sure why it's not working. please help.
thanks
Why not using $now['mon']; ? 1-12
And later if ($i == $now['mon']) ?
Jul 12 '08 #2
thx, that works!

but, i'm still wondering, why wouldn't my previous code work?

On Jul 12, 10:14 am, Olaf Schinkel <tr...@schinkel.tvwrote:
whatchamakeofit schrieb:
hi. i have the following code:
$now=getdate();
$currMonth = $now["month"];
$currYear = $now["year"];
$currDay = $now["mday"];
for($i=1; $i<=12; $i++){
$month = date("F",mktime(0, 0, 0, $i));
if ($month == $currMonth)
echo "<option value='".$month."' selected='selected'>".$month."</
option>";
else
echo "<option value='".$month."'>".$month."</option>";
}
all i want to do is dynamically output a selection box containing all
the months of the year, and have the selection default to the current
month. however, i'm not sure why it's not working. please help.
thanks

Why not using $now['mon']; ? 1-12
And later if ($i == $now['mon']) ?
Jul 12 '08 #3
whatchamakeofit wrote:
hi. i have the following code:

$now=getdate();
$currMonth = $now["month"];
$currYear = $now["year"];
$currDay = $now["mday"];
for($i=1; $i<=12; $i++){
$month = date("F",mktime(0, 0, 0, $i));
if ($month == $currMonth)
echo "<option value='".$month."' selected='selected'>".$month."</
option>";
else
echo "<option value='".$month."'>".$month."</option>";
}

all i want to do is dynamically output a selection box containing all
the months of the year, and have the selection default to the current
month. however, i'm not sure why it's not working. please help.
thanks
Works for me.

--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
Nothing he's got he really needs
Twenty first century schizoid man.
***********************************

Jul 12 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

45 posts views Thread by Market Mutant | last post: by
3 posts views Thread by Job Lot | last post: by
3 posts views Thread by JazeMail | last post: by
3 posts views Thread by Robert Dell | last post: by
1 post views Thread by Lisa | last post: by
4 posts views Thread by Working_Girl | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.