Jump to content

Display blog archives by month


majocmatt

Recommended Posts

It doesn't have to be a blog, but how would I go about making a script that grabs entries out of my mysql database by month, like current blogs do?

 

January 2007

December 2006

November 2006

etc,etc

 

I've searched on mysql's website, but i don't really understand how it works, still. I don't even care if there's nothing in one of those months, I would just like to display the last 3 months or so.

 

Any help?

Link to comment
https://forums.phpfreaks.com/topic/39201-display-blog-archives-by-month/
Share on other sites

It depends on how the date is being stored in the MySQL database.

 

I actually prefer my own timestamp sorting method which goes as so:

 

<?php
$now=date("YmdHis"); // Creates a string of the current date and time
?>

 

Store that variable in your mysql database, then if you want to find any entry in the last three months, search for something like this:

 

<?php
$search=date("YmdHis");
$search-=300000000;
?>

 

Now in your SQL where clause, say " WHERE `date` > '{$search}'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.