Jump to content


Photo

Listing last few months


  • Please log in to reply
2 replies to this topic

#1 matfish

matfish
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts
  • LocationUK

Posted 01 June 2006 - 08:02 AM

Hi,

All im trying to do is list the last 4 months like:-

June
May
April
March

Firstly 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:


// this prints the curent month
echo "<p><a href='/resources/blog_archive_view.php?arch=".date("Ym")."'>".date("F")."</a></p>";


// this should print the last 3 months
for ($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);
                
}

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.




#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 01 June 2006 - 08:13 AM

for($i=0;$i<4;$i++) {
   echo $lastmonth = date("F y", mktime(0, 0, 0, date("m")-$i, date("d"),   date("Y")));
   echo "<br>";
}

if you dont want to display current month....start loop with $i=1 instead of $i=0

hth
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 matfish

matfish
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts
  • LocationUK

Posted 01 June 2006 - 09:15 AM

Thank you! It works a treat!

Thanks for the prompt reply

;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users