views:

171

answers:

2

I have a table of Calendar event information (Date, username).

I want to print the following information for each "event" for a selected month in a table, using PHP and MySQL:

 SELECT DAYOFWEEK( eventDate ) AS
 DAY , YEAR( eventDate ) AS YEAR, `primary` , secondary, weekend
 FROM eventcal
 WHERE region = 4
 AND MONTH( eventDate ) =7
 ORDER BY DAYOFWEEK( eventDate )

There can be multiple users associated with a given day. What's the best way to, using MySQL and PHP, build the table so that the usernames sharing a common day are merged together? For example, instead of:

 June | 7 | 2009 | doej2
 June | 7 | 2009 | smithj2
 June | 8 | 2009 | mccoyj2

I want...

 June | 7 | 2009 | doej2, smithj2
 June | 8 | 2009 | mccoyj2

Any ideas? Thanks!

+4  A: 

Same question as: Grouping in SQL

Suggested was to use MySQL's GROUP_CONCAT

Vincent
Ah, didn't know about this. SQL keeps surprising me! Thanks
behrk2
+1  A: 

GROUP_CONCAT is your keyword. Example : http://www.mysqlperformanceblog.com/2006/09/04/group_concat-useful-group-by-extension/

Ahmet Kakıcı
Good example, thanks!
behrk2