Best way to display a list of events by month
Posted
by EmmyS
on Stack Overflow
See other posts from Stack Overflow
or by EmmyS
Published on 2010-05-22T00:04:35Z
Indexed on
2010/05/22
0:10 UTC
Read the original article
Hit count: 619
I have a mySQL table of events and want to display them in a list using PHP. Pretty simple, except I only want to display the month name once, for example:
May 2010
12th, 7 pm. Event 1 - event one description
15th, 5:30 pm. Event 2 - event two description
June 2010
9th, 7 pm. Event 1 - event one description
11th, 5:30 pm. Event 2 - event two description
I'm very new at SQL and PHP. I can think of one way to do it. It would involve selecting all records grouped by date, then looping through all records, comparing the month/year value each time and the first time the month/year doesn't match, print a new header row to my HTML table. I can't believe it's the best or most efficient way to go. Any ideas for a newbie? I'm sure my way would work, but it's inelegant at best, and processor-intensive at worst.
© Stack Overflow or respective owner