I have the following data model
Table: User
USER ID
USER NAME
Table: Group
GROUP ID
GROUP NAME
Table: User Group
GROUP ID
USER ID
I am trying to display a screen with all group names and associated users - the front end is PHP
The query I have is as below -
`SELECT a.group_id,
a.group_name,
GROUP_CONCAT(g.user_id) AS user_ids,
GROUP_CONCAT(u.user_fname) AS user_names
FROM group a, user_group g, user u
WHERE a.group_id = g.group_id
AND g.user_id = u.user_id
GROUP BY a.group_id`
My question : As you can see from the above query - I have to have two lists of concatenated strings that represent user ids and user names. This becomes a headache in PHP as I have to 1. Explode both concatenated strings into arrays 2. Run a loop through both arrays and construct User objects from them 3. Then pass the array of objects over
Is there a more efficient / better way to do this? Any suggestions, pointers would be appreciated.