TwelvestoneBack End

Group mysql DB entries by month and year


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
woo-d
 
2009-08-01

So i'm creating a simple news system with php mysql.

I am storing the date of each news post as a date field in a mysql database.

I need to be able to query the DB and group the news posts by month and date and display archive links in the sidebar like this

Archive November 2008 December 2008 January 2008

etc.

any help would be appreciated.

Thanks

scudsucker
 
2009-08-01

The word 'group' explains exactly what you need. This sort of thing should do the trick:

SELECT MONTHNAME(dateCoumn) AS month, YEAR (dateCoumn) As year

       FROM news

       GROUP BY 

      YEAR (dateCoumn),
      MONTHNAME(dateCoumn)

      ORDER BY 
      dateCoumn ASC
woo-d
 
2009-08-01

Yeah that looks like what I need. Thanks.

How do i then get the monthname and year echoed out on the page?

woo-d
 
2009-08-01

nevermind. I figured it out. Thanks for you help. Much appreciated.

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneBack End

Group mysql DB entries by month and year