Hello:
I have part of a script which produces a drop down box listing the months of the year.
Can someone walk me through some of the lines for this section of the script? I'm not quite sure about some of the lines.
The portion of the script is below.
My specific question relates to the following lines:
for ($x=1; $x <= count($months); $x++) {
echo"<option value=\"$x\"";
if ($x == $month) {
echo " SELECTED";
}
echo ">".$months[$x-1]."";
}
I know in the first line a counter is being set. The second line will list the options that meet the conditions for the counter.
Line 4....what is this echo " SELECTED"; statement doing? Is it necessary? Where is SELECTED coming from? It's not a defined variable anywhere in the script?
The final echo statement is confusing. I don't understand why you are subracting from from the counter?
Thank you for taking the time to explain this to me.
===========================
$month = $POST['month'];
$year = $POST['year'];
<form method="post" action="<?php echo "$_SERVER[PHP_SELF]"; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
for ($x=1; $x <= count($months); $x++) {
echo"<option value=\"$x\"";
if ($x == $month) {
echo " SELECTED";
}
echo ">".$months[$x-1]."";
}
?>
</select>
<select name="year">
<?php
for ($x=1980; $x<=2010; $x++) {
echo "<option";
if ($x == $year) {
echo " SELECTED";
}
echo ">$x";
}
?>
</select>
<input type="submit" value="Go!">
</form>