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.
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.
精彩评论