BetaONE will rise again!


Reply
  #1  
Old 5th Jan 04, 04: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
  #2  
Old 5th Jan 04, 07:14 PM
SlickVic78's Avatar
SlickVic78 SlickVic78 is offline
Senior Member
 
Join Date: Sep 2001
Location: New York, USA
Posts: 515
SlickVic78 is an unknown quantity at this point
Hey JacKDynne,

So your code right now will post from this year and up, not past years correct?

The issue falls within this statement:

Code:
for ($x=$currYear; $x<($currYear+5); $x++)
You have set $x to equal the current year, you set your limit to have $x be less than 5 years after the current year, and you set your counter to always increment by 1.

If you were to set the limit to look like this $x<($currYear-5), this still doesn't work (as you already noticed), because the current year has already succeeded the limit (being you are comparing the current year,($x, with being less than 5 years before the current year) which makes this statement already false, therefore, no years should have been posted when you have tried that out...

I think what you can do is this, to get at least 5 years before the current year:

Code:
for ($x=$currYear-5; $x<($currYear+5); $x++)
This way you set $x to being 5 years before the current year and the limit should be 5 years after the current year.

See if this helps, if not, let me know and I'll look into it further...

-SlickVic78
__________________
  • Pentium 4 3.20GHz Processor
  • 1 Gig DDR 400MHz RAM
  • 100 Gig 7200 RPM Western Digital HDD
  • 80 Gig 7200 RPM Western Digital HDD
  • Lite-On LTR-52327S CD-RW Burner
  • Lite-On SOHW-1633S DVD Burner
  • ATI Radeon 9700 Pro
  • Sound Blaster Audigy
  • Microsoft Windows XP Pro SP-2
Reply With Quote
  #3  
Old 5th Jan 04, 08:48 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
You rock SlickVic

That was just about the only variation I did not try

Thanks for the help m8 - I appreciate it

/JD
__________________


Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Uh, oh I have a feeling Wal-Mart might be in some trouble!! Dijital Chit Chat 0 2nd Nov 04 10:12 PM
Consistant trouble with motherboard of other hardware. Darkwolven Hardware Support 2 14th Mar 02 04:40 AM


All times are GMT +1. The time now is 05:21 AM.


Design by Vjacheslav Trushkin for phpBBStyles.com.
Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.