Page 1 of 1

Returning data from a table by year

Posted: Fri Jul 31, 2009 9:47 am
by hairyjim
Hi,

Any insight into the following would be good.

I have a MySQL table with data going back several years. I wish to retrieve the data from the table in year order but in recordsets of years & months.

So I wish to query the table and bring back the current year data, broken down by month and insert each month's records into an HTML table but each month to have its own table.

Jan 2009
record 1
record 2
record 3

Feb 2009
record 4
record 5
record 6
record 7

March 2009
record 8
record 9...and so on

Re: Returning data from a table by year

Posted: Fri Jul 31, 2009 9:56 am
by VladSun

Re: Returning data from a table by year

Posted: Fri Jul 31, 2009 9:57 am
by spider.nick
This is belongs in the database section.

Anywho, I am not a MySQL guru. However, I would probably do it the following way:

Code: Select all

SELECT m, y, record_num FROM records ORDER BY m ASC, y ASC, record_num ASC
Then you would use PHP to manipulate the data into the tables.

Nick

Re: Returning data from a table by year

Posted: Fri Jul 31, 2009 10:38 am
by hairyjim
VladSun wrote:That's called "grouping" :)

http://www.garfieldtech.com/blog/php-group-by

...thanks! I knew this technique had a name I just couldn;t figure out what it was! I have starting point thanks!

Re: Returning data from a table by year

Posted: Fri Jul 31, 2009 2:34 pm
by VladSun
spider.nick wrote:This is belongs in the database section.
IMHO, PHP-code is the appropriate section for this question.

Re: Returning data from a table by year

Posted: Fri Jul 31, 2009 5:02 pm
by spider.nick
hairyjim wrote:
VladSun wrote:That's called "grouping" :)

http://www.garfieldtech.com/blog/php-group-by

...thanks! I knew this technique had a name I just couldn;t figure out what it was! I have starting point thanks!
From the posters question:
I have a MySQL table with data going back several years. I wish to retrieve the data from the table in year order but in recordsets of years & months.
Nick