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.

Did you know?Explore Trending and Topic pages for more stories like this.
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 Like 16 Dislike
Previous forums Next forums
Other forums

error with opendir
when i do this

if ($handle = opendir($dir)) {
while (false !== ($file = readdir($han

output_buffering so rewrite
I'm planning to rewrite some of my scripts so they don't have to use output buffering to accomplish

convert static html data into dynamic
hi all

i need to convert a website which has static above 2000 articles into dynamic and add

Add User script "Could not execute query"
This should be an easy script but I can't get it to run. Can someone please help me?

<

SuperCali PHP Event Calendar
does anyone have any experience with the SuperCali PHP Event Calendar? I could use some assistance

Could Someone Please Debug This?
I was wondering if someone could debug this script for me. I realize it's not the tidest script (and

convert PHP array to Javascript array
I have a page that gets a request sent from AJAX, and I am trying to convert a PHP array to a javasc

passthru() help
Hi everyone,
I'm new to the forum and to PHP. I have some pretty good experience writing shell sc

a dificult string search
Hi I don't know a way around this. I want the user to input a password, but to make it a bit complca

How to Create a Dynamic table
col1 col2 date1 date2 date3 date4..........
a b v1 v2 v3 v4

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash