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
foreach loop, assistance request
I would like some guidance on the usage of foreach as I try to parse through a large database and wh
PDO returns erroneous columns from within pdt
Hi All,
This is a truly weird behavior:
When using a simple pdo fetch, erroneous columns a
Pipe email to PHP - get mail adress from MySQL - send?
Hi all,
this is the challenge:
1) Our faculty at the college where I'm employed includ
Sessions Value Not Saved
Hi,
Im making a login form and im using this code:
Code: if($login=="true"){
PHP Programming error. Please help!
Hi there,
Am making a website for a friend and have encountered a problem that i need fixing
PHP webpage & array print issue
I have this code running, and it works perfectly … however, see my bottom bit about what I see
links using header()
Hi All
I'm not sure where to ask for help on this but I hope someone can offer some. I'm at
PHP & Java
Hello,
can PHP code be used inside java code?
Code: <SCRIPT LANGUAGE="Java
how to make database item unique
Hey guys,
is it possible to do this:
I have the database item $title being pulled for
Easy administration on MySQL databases
My website is database driven and I am very tired of manually making queries to my tables in order t