majocmatt Posted February 19, 2007 Share Posted February 19, 2007 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? Quote Link to comment Share on other sites More sharing options...
tom100 Posted February 19, 2007 Share Posted February 19, 2007 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}' Quote Link to comment Share on other sites More sharing options...
majocmatt Posted February 19, 2007 Author Share Posted February 19, 2007 I store as a SQL DATE format (YYYY-MM-DD) ... so if I call something like this: $month_now = date("m"); SELECT * FROM myTable WHERE date > DATEADD(m, -3, $month_now) How do I get it to recognize each entires Month, and display as I listed above? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 19, 2007 Share Posted February 19, 2007 Look here: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.