rvdb86 Posted October 29, 2009 Share Posted October 29, 2009 I really hope this is not a case of working with code for the whole day and I have failed to spot an obvious mistake but I am trying to out put a list of the next 10 years (eg 2009, 2010....2018, 2019) heres my code: <?php $y = date('Y'); $l = 1; while ($l <= 10){ ?> <option value="<?php echo $y; ?>"><?php echo $y; ?></option> <?php $plusOne = strtotime(date("Y", strtotime($y)) . " +1 year"); $y = date('Y', $plusOne); $l++; } ?> It only increases the date to from 2009 to 2010 and then repeats 2010 nine times TIA for any suggestions! Link to comment https://forums.phpfreaks.com/topic/179515-solved-looping-date-problem/ Share on other sites More sharing options...
mpharo Posted October 29, 2009 Share Posted October 29, 2009 Your $plusOne variable is not increasing, therefore returning the same result each time. You will need to change the +1 year to include the $l variable... <?php $y = date('Y'); $l = 1; while ($l <= 10){ ?> <option value="<?php echo $y; ?>"><?php echo $y; ?></option> <?php $plusOne = strtotime(date("Y", strtotime($y)) . " +$l years"); $y = date('Y', $plusOne); $l++; } ?> Link to comment https://forums.phpfreaks.com/topic/179515-solved-looping-date-problem/#findComment-947240 Share on other sites More sharing options...
rvdb86 Posted October 29, 2009 Author Share Posted October 29, 2009 great thanks for your help. works perfectly. I hadn't thought of that, I was expecting the y variable to contain the increased date and therefore I only increased it by 1 each time. Anyway thanks again! Link to comment https://forums.phpfreaks.com/topic/179515-solved-looping-date-problem/#findComment-947245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.