matfish Posted June 1, 2006 Share Posted June 1, 2006 Hi,All im trying to do is list the last 4 months like:-JuneMayAprilMarchFirstly my code done the first two correctly but then would continue the 2nd month down the rest of the page. My current attempt worked yesterday (still being in May) but then looking today (1st June) its messed up again, its missing May.Iv got:[code]// this prints the curent monthecho "<p><a href='/resources/blog_archive_view.php?arch=".date("Ym")."'>".date("F")."</a></p>";// this should print the last 3 monthsfor ($m = 3; $m > 0; $m--){$last4month = mktime(0, 0, 0, date("m", $last)+$m, date("d", $last), date("Y", $last)); echo date("F y",$last4month); }[/code]Ideally would like to get rid of the first echo and just have it loop the last 4 months, including this (current) month.Any ideas/point me in the right direction to a script etc.. would be appreciated!Thanks for you time. Quote Link to comment https://forums.phpfreaks.com/topic/10935-listing-last-few-months/ Share on other sites More sharing options...
samshel Posted June 1, 2006 Share Posted June 1, 2006 [code]for($i=0;$i<4;$i++) { echo $lastmonth = date("F y", mktime(0, 0, 0, date("m")-$i, date("d"), date("Y"))); echo "<br>";}[/code]if you dont want to display current month....start loop with $i=1 instead of $i=0hth Quote Link to comment https://forums.phpfreaks.com/topic/10935-listing-last-few-months/#findComment-40829 Share on other sites More sharing options...
matfish Posted June 1, 2006 Author Share Posted June 1, 2006 Thank you! It works a treat!Thanks for the prompt reply;) Quote Link to comment https://forums.phpfreaks.com/topic/10935-listing-last-few-months/#findComment-40847 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.