...

View Full Version : date in hyperlink problem due to new year



jasonc310771
01-01-2008, 10:58 PM
Hi

My code i have will not set the links for last years months to last years number, it is showing this years.

I have looked at the code and tried to change it so it puts the year for previous months but just can not get my head around it at all.

say it shows as it will next month...


JAN DEC NOV OCT SEP AUG JUL JUN


i need the DEC to JUN to have a link going to say

JAN to go to ?m=01&y=2008
and DEC to go to ?m=12&y=2007
and the rest from NOV to JUN to have a link also to 2007's date..

can anyone suggest the best way to do this as it is starting to give my a real headache and i have been looking at this most of the day.

I was first told to use the DATE command and minus one month and then get the month and year and set my links that way but this was the method i used in the first place and this failed not sure why but opted for this method as it worked all the time but now i face the new year problem of showing previous months with their correct years in the hyperlink.

thanks in advance for your help.


<?
$months=array (1=>"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
$date=strtoupper(date("M"));
$key=array_keys($months,$date);
$count=1;
for ($loop=1; $loop<=count($months); $loop++) {
$key[0]--;
if($key[0]==0){
$key[0]=12;
}
?>
<a href="?m=<?php echo(sprintf("%02d",$key[0]).'&amp;')?>y=<?php echo(gmdate("Y"))?>" STYLE="text-decoration: none"><b><?php echo($months[$key[0]])?></b></a>
<?php
if($count==8){
break;
}
$count++;
} ?>

mic2100
01-02-2008, 02:09 AM
hi,

i have made a few change to your code but i think it should work now as you want it to. if you are wanting it to do more that 12 months then it will need some more tweaking.



<?
$months=array (1=>"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
$date=strtoupper(date("M"));
$key=array_keys($months,$date);
$count=1;
$marker = 0;

for ($loop=1; $loop<=count($months); $loop++)
{

$key[0]--;
$year = gmdate('Y');

if($key[0] == 0)
{

$key[0]=12;
$marker = 1;

}

if($marker == 1)
{

$year = gmdate('Y') - 1;

}

?>
<a href="?m=<?php echo(sprintf("&#37;02d",$key[0]).'&amp;')?>y=<?php echo $year; ?>" STYLE="text-decoration: none"><b><?php echo($months[$key[0]])?></b></a>
<?php

if($count==8)
{

break;

}

$count++;

}
?>

jasonc310771
01-02-2008, 02:54 AM
ah i think from reading the code it will only minus 1 from the year if the month is DEC ?

if so, not what i mean sorry.

here is what i mean i hope this explains it more...


say todays month is DEC then it shows NOV though to MAY ( the last 8 months of the archives) the DEC link is not shown in this right side list as it is already shown in the page by default.

so when they click DEC it would last years december have the hyperlinks be all in 2007.

but now we are in 2008 the links now need to show as this...

DEC, NOV.... to JUN but this time should show the hyper links as this....

when they click DEC it will show link for DEC 2007 and all the others in 2007 too


but now when they come to next month FEB it will show the link for...
JAN, DEC, NOV,..... (for 8 month back)

and this time the links will be
JAN 2008, DEC 2007, NOV 2007..... and so on.

jasonc310771
01-02-2008, 02:58 AM
on reading it once more i see that 'marker' is set outside the for loop and will stay set to 1 if 12 is reached meaning it will keep minusing one from the year.

so yes it seems it should work

sorry should have tried it first, will check code now

thanks for your help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum