开发者

mysql_fetch_array by date php

I have a list of fixtures in a table in my database. They have the following columns:

hometeam, awayteam, date, time

At the moment I used fetch array to write out a big table:

Fulham v Aston Villa | 13/08开发者_StackOverflow中文版/2011 | 15:00
West Bromwich Albion v Manchester United | 13/08/2011 | 15:00
Liverpool v Sunderland | 13/08/2011 | 15:00

etc etc

What I wanted to do is have it slightly different:

13/08/2011 | 15:00
Fulham v Aston Villa
West Bromwich Albion v Manchester United
Liverpool v Sunderland

20/08/2011 | 15:00
Arsenal v Liverpool
Bolton v Manchester City
etc etc

can someone help me to understand the best way to do this please?


Sort your data by date (add ORDER BY DATE to the query) and then just display. Keep track of when the date changes so that you only need to print the date when it changes.


You want to group the teams by date. You'll want to use GROUP BY date, time. This will order all the teams using the date.


Maybe you are looking for a query like this:

SELECT date, time, GROUP_CONCAT(
    CONCAT(hometeam, ' v ', awayteam) ORDER BY hometeam, awayteam
    SEPARATOR '\n'
  ) AS fix
FROM fixture
GROUP BY date, time
ORDER BY date DESC;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜