Think
Think

Reputation: 3

Php Arrays / Sort by Date

How would you go about implementing an array design and function to achieve the following table in php. The data would be drawn from a mysql database but i would like to limit the number of mysql queries required and therefore use a formatted array of some sort.

-----------------------------------------
|           | 2009 | 2008 | 2007 | 2006 |
-----------------------------------------
| country a | d d  |      | doc  | doc  |
| country b |      | doc  | doc  |      |
| country c | doc  | d d  |      | doc  |
| country d | doc  |      | d d  |      |
-----------------------------------------

Where both d & doc are documents. And any date(y) / country can have many documents. The resulting table would be an html table.

Upvotes: 0

Views: 176

Answers (1)

Soviut
Soviut

Reputation: 91714

You should not be using arrays to manipulate or group data if you can help it. Try to get mySQL to do all the heavy lifting.

For example:

...GROUP BY YEAR(item_date)

Have a look at the Time Functions in mySQL.

Upvotes: 1

Related Questions