westondunn Posted May 22, 2013 Share Posted May 22, 2013 I need help displaying more than 12 months on this project. I can't seem to make this loop work without repeating months of the year. All I really need is to display more than 12 months at a time. echo" ";date_default_timezone_set('America/Los_Angeles');$dateComponents = getdate();$month = $dateComponents['mon'];$year = $dateComponents['year'];$max = 0;while($max < 12){if($month == 13){$month = 1;$year++;}$thisMonth = date("F", mktime(0, 0, 0, $month, 1, 2012));echo "#$thisMonth$year";$month++;$max++;}echo " ";?> Link to comment https://forums.phpfreaks.com/topic/278288-help-display-more-than-12-months/ Share on other sites More sharing options...
requinix Posted May 22, 2013 Share Posted May 22, 2013 while($max Probably don't want a maximum of 12 months, right? Link to comment https://forums.phpfreaks.com/topic/278288-help-display-more-than-12-months/#findComment-1431651 Share on other sites More sharing options...
westondunn Posted May 22, 2013 Author Share Posted May 22, 2013 If I change this to: while($max < 24){if($month == 13){ Then will it start the new year from 13 and then continue? I will try to make sure, just getting your explanation. Link to comment https://forums.phpfreaks.com/topic/278288-help-display-more-than-12-months/#findComment-1431662 Share on other sites More sharing options...
AbraCadaver Posted May 22, 2013 Share Posted May 22, 2013 Only once through the loop will it be the 13th month. So for the next 24 months: while($max < 24){ if($month % 13 == 0) { Link to comment https://forums.phpfreaks.com/topic/278288-help-display-more-than-12-months/#findComment-1431663 Share on other sites More sharing options...
westondunn Posted May 22, 2013 Author Share Posted May 22, 2013 Awesome! Thanks you two! Worked like a charm! Link to comment https://forums.phpfreaks.com/topic/278288-help-display-more-than-12-months/#findComment-1431664 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.