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
16
Other forums
Quick variable question
hey guys/gals,
im trying to write a php script and it works fine as i have it, but i need to set
first id from db not showing
I have a php script which displays the content of a mysql table as a html table with sorting, delete
An odd assignment statement. Can someone explain this assignment to me?
What purpose is served by the bit of code between the two equal signs in the $installurl set? Is th
Display the user's weight lost in the past week
Hello everyone,
I am working on a weight loss app for my site, and I want to display the user
writing a screen scraper
Hello,
I'm writing a screen scraper application and want to be able to get absolute addresses
utf8_general_ci error ??
I have all kinds of data to be inserted in database table
//I am getting this error
Yo
Alternate messaging
I have 4 strings in MySQL db1
$string1 : Hello
$string2 : Hi
$string3 : Great
$strin
drop-down with sub-category appear
Hello,
i know how to build a simple dro-down list, im looking for a code when im gonna choose
xml element exists
Code: [Select]<?xml version="1.0"?>
<Addresses>
<
PHP and MySQL on intranet?
Is it possible to use both these on an intranet network?