I am using this php code to generate a month/day/year pull down menu but I cannot set it to pull previous years from the pulldown, only the current year + . Any ideas on how to resolve this?
Here is the area in question:
// generate year drop-down
echo "<select name=" . $prefix . "y>";
for ($x=$currYear; $x<($currYear+5); $x++)
{
$str = "<option value=$x";
if ($x == $currYear)
{
$str .= " selected";
}
$str .= ">" . sprintf("%04d", $x) . "</option>";
echo $str;
}
echo "</select>";
Here is the full code:
// function to format DATE values
function fixDate($val)
{
// split it up into components
$datearr = explode("-", $val);
// create a timestamp with mktime(), format it with date()
return date("d M Y", mktime(0, 0, 0, $datearr[1], $datearr[2], $datearr[0]));
}
// generate three list boxes for d-m-y selection
function generateDateSelector($prefix="")
{
// month array
$monthArray = array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
// get current year, month and date
$arr = getdate(mktime());
$currYear = $arr["year"];
$currMonth = $arr["mon"];
$currDay = $arr["mday"];
// generate date drop-down
echo "<select name=" . $prefix . "d>";
for ($x=1; $x<=31; $x++)
{
$str = "<option value=" . sprintf("%02d", $x) . "";
if ($x == $currDay)
{
$str .= " selected";
}
$str .= ">" . sprintf("%02d", $x) . "</option>";
echo $str;
}
echo "</select>";
// generate month drop-down
echo "<select name=" . $prefix . "m>";
for ($x=1; $x<=12; $x++)
{
$str = "<option value=" . sprintf("%02d", $x) . "";
if ($x == $currMonth)
{
$str .= " selected";
}
$str .= ">" . $monthArray[$x] . "</option>";
echo $str;
}
echo "</select>";
// generate year drop-down
echo "<select name=" . $prefix . "y>";
for ($x=$currYear; $x<($currYear+5); $x++)
{
$str = "<option value=$x";
if ($x == $currYear)
{
$str .= " selected";
}
$str .= ">" . sprintf("%04d", $x) . "</option>";
echo $str;
}
echo "</select>";
}
?>
I tried changing this:
$x<($currYear+5); to this:
$x<($currYear-5); and some other variations but that does not seem to work. Any ideas while I keep researching?
Many TIA's to any who reply
/JD