fonster_mox Posted May 9, 2009 Share Posted May 9, 2009 Hi, I do not know any php, just wanted to clear that up first! I have a mysql database with the following fields: datetime, title, body and id. Where datetime is automatically inputted in the format $datetime = date ("Y-m-d H:i:s"); What I would like now is a .php code which lists all months (eg, May 2009, June 2009) if they are present and then when you click on a month, you echo all news entries from that month, much like this - or possibly using a drop down box. As I said I don't really know php so I don't know where to start, can anybody help me with the code or perhaps point me in the right direction? Would be much appreciated, thanks for reading Quote Link to comment Share on other sites More sharing options...
semlabs Posted May 9, 2009 Share Posted May 9, 2009 You can order database entries using SQL. In your SQL query just do something like: SELECT datetime FROM table ORDER BY datetime DESC Alternatively, you can use ASC instead of DESC to sort the results in ascending order. Quote Link to comment Share on other sites More sharing options...
fonster_mox Posted May 9, 2009 Author Share Posted May 9, 2009 Sorry I dont' think I explained my problem very well, I already have sorted them, well I sorted them by id which is an auto incrementing number which essentially does the same thing. What I would like is sort of an archive webpage, where the php generates a list of months, and clicking on a month would take you to all posts from that month. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 SELECT * FROM table WHERE datetime BETWEEN date1 AND date2 That should get all the entries where datetime is between 2 dates. You'll have to fill in the 2 dates of course. I feel like you can use MySQL INTERVAL for this, but I never had great luck with using that. 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.