Sort Alternative/bi-monthly
Posted on
16th Feb 2014 07:03 pm by
admin
Hi all,
Am going mad trying to get something to work.
I'm creating a CMS for a magazine. The magazine is published every 2 months and therefore the edition is nov-dec or jan-feb etc.
I've an archive option on the site and rather than listing:
dec
nov
oct
sept etc
I'd like to follow the magazine editions:
nov-dec
sept-oct
The code I have so far is:
echo '<p>Sort By:</p>';
$year = date("Y"); //get the current year
$startDate = "1 january".$year; // set the end date to current year
function printMonths($var)
{
$start = strtotime($var); //timestamp of the entered date
$now = strtotime("Now"); //timestamp of now so it does not write anything in the future
while ($now > $start) //while the start is less than now
{
echo '<a href="news_archive.php?s=&id=' . get_id() . '&month=' . date("F", $now) .'">'.date("F", $now).'</a>';
echo " | ";
$now = strtotime("-1 month", $now); // subtract a month from the start timestamp
}
}
printMonths($startDate); //execute the function
this works well listing the months from the current month back. But this is not what I need. If I alter the line
$now = strtotime("-1 month", $now);
to
$now = strtotime("-2 month", $now);
It starts in Nov and goes back to sept which is not right. It also doesn't show nov-dec etc.
Any help on this is much appreciated
No comments posted yet
Your Answer:
Login to answer
92
16
Other forums
private constructor
Hello,
Can we create a constructor as private? If yes, what is the use of it? If no, why can'
how to get IP address?
hey guys,
i have this code which is supposed to get me the IP address of my site visitors:
post to self
Trying to get my form to submit to itself. However I am also trying to use an image for my submit bu
Reduce redundancies in switch functions?
Hello all! I somewhat new to PHP, and was wondering if anyone could give some suggestions on a swit
JQuery, Masterpage, and Control issue
Hey everyone, I am using JQuery in several sites so I thought it would be best to place the library
Array becomes unset by itself?
Hi,
I have a bit of experience with PHP but not extensive. It seems I cannot store any items
function to return url
Hi,
Can you guys help me giving a function that takes all the contents in a particular field
Memory Allocation
Hi folks,
see this ex:
int v=5;
v=v+10;
then what will do the compiler before th
need help in php variable
i have a php variable on one page
Code: [Select]$lastId = mysql_insert_id($db);
echo $lastId;<
confused between ' ' and " "
there is a php i set:
$begin_date_query = mysql_query( "SELECT SUBDATE(due_date, INTERVAL $d