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 Like 16 Dislike
Previous forums Next forums
Other forums

Regarding accessing SQL query issued by any user in Oracle 10g
Hi all,
i want to know the queries issued by various users accessing a database...

php forms and database navigatio
Hello,
I'm new to php and i'd like to post the following.
I have written code to get records f

Advice on how to delete a mysql row using my form
Hi,

I am very new to php and am struggling to work out how to delete a portfolio item (a row

unexpected T_STRING
error log "[Sat Jan 09 18:27:58 2010] [error] [client 127.0.0.1] PHP Parse error: syntax error

Displaying different page content, depending on the logged in user.
Hi all, I am new to ASP.net (and web development in general), and have a question about how I can di

How to read posted binary data from a mobile device and post it to a web server?
Here is the senario...

I have a mobile device (MD) that posts binary data to a Web Server (WS

Click counter to ignore traffic from search bots
I have a click counter on my site that...well, counts the number of clicks a link gets on the frontp

PHP loop
Okay so I have several "articles" stored in a mysql database and am attempting to echo tho

insert mysql embeded videos as blobs?
Using TinyMCE my client will be able to embed images and flash videos into large columns of text whi

Calling a Procedure with IN & OUT Parameters
Hello,

I usually call my procedures using the following way

declare variable e

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