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
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}'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.