View Single Post
  #1  
Old 5th Jan 04, 03:20 PM
JacKDynne's Avatar
JacKDynne JacKDynne is offline
Administrator
 
Join Date: Oct 2001
Location: The Past Through Tomorrow
Posts: 1,591
JacKDynne will become famous soon enoughJacKDynne will become famous soon enough
Send a message via MSN to JacKDynne
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:
Code:
// generate year drop-down echo "<select name=" . $prefix . "y>"; for ($x=$currYear; $x<($currYear+5); $x++) { $str = "<option value=$x"; &nbsp;if ($x == $currYear) &nbsp;{ &nbsp;$str .= " selected"; &nbsp;} $str .= ">" . sprintf("%04d", $x) . "</option>"; echo $str; } echo "</select>";
Here is the full code:

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) . ""; &nbsp;if ($x == $currDay) &nbsp;{ &nbsp;$str .= " selected"; &nbsp;} $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) . ""; &nbsp;if ($x == $currMonth) &nbsp;{ &nbsp;$str .= " selected"; &nbsp;} $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"; &nbsp;if ($x == $currYear) &nbsp;{ &nbsp;$str .= " selected"; &nbsp;} $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
__________________


Reply With Quote