djones Posted January 5, 2008 Share Posted January 5, 2008 I'm trying to list the current year and past X many years in a select box. I'm gett the current year printed for all... <?php $i = 0; while ($i < 80) { $y = date("Y") - 1; echo '<option value="'.$y.'">'.$y.'</option>'; $i++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84662-list-current-and-past-years-in-select-box/ Share on other sites More sharing options...
mrdamien Posted January 5, 2008 Share Posted January 5, 2008 I think you meant to subtract $i and not 1... since $i is your variable, and 1 is always 1. <?php $i = 0; while ($i < 80) { $y = date("Y") - $i; echo '<option value="'.$y.'">'.$y.'</option>'; $i++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84662-list-current-and-past-years-in-select-box/#findComment-431459 Share on other sites More sharing options...
Psycho Posted January 5, 2008 Share Posted January 5, 2008 I think a for loop would be more appropriate in this instance: <?php for ($year=date("Y"); $year>=(date("Y")-80); $year--) { echo "<option value=\"$year\">$year</option>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84662-list-current-and-past-years-in-select-box/#findComment-431461 Share on other sites More sharing options...
djones Posted January 5, 2008 Author Share Posted January 5, 2008 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/84662-list-current-and-past-years-in-select-box/#findComment-431473 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.