Connecting Tech Pros Worldwide Help | Site Map

comparing months not working

whatchamakeofit
Guest
 
Posts: n/a
#1: Jul 12 '08
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
Olaf Schinkel
Guest
 
Posts: n/a
#2: Jul 12 '08

re: comparing months not working


whatchamakeofit schrieb:
Quote:
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']) ?
whatchamakeofit
Guest
 
Posts: n/a
#3: Jul 12 '08

re: comparing months not working


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:
Quote:
whatchamakeofit schrieb:
>
Quote:
hi. i have the following code:
>
Quote:
$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>";
}
>
Quote:
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']) ?
Chuck Anderson
Guest
 
Posts: n/a
#4: Jul 12 '08

re: comparing months not working


whatchamakeofit wrote:
Quote:
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.
***********************************

Closed Thread