I'm somewhat new with php/mysql so I'm sure I'm missing something. This approach probably isn't the best either.
I have the following tables
Table: unit_members Fields: id, unit_id, person_id, primary
Table: persons Fields: id, name, rank_id
Table: ranks Fields: id, name, rank
Table: units Fields: id, name, rank
I'm trying to display each unit and the persons in each unit and have the persons sorted by rank which is an int field. It seems simple, but I'm unable to get the persons to be ordered by rank.rank.
Here's my query:
'SELECT unit_members.person_id, GROUP_CONCAT(persons.id) as personid,
GROUP_CONCAT(persons.name) as name, persons.rank_id, unit_members.unit_id,
units.id as unitid, units.name as unit,
GROUP_CONCAT(DISTINCT units.codename) as squad, ranks.id as rankid,
GROUP_CONCAT(ranks.rank) as rankrank
FROM unit_members, ranks, persons, units
where persons.rank_id = ranks.id
and units.id = unit_members.unit_id
and persons.id = unit_members.person_id
group by units.codename
ORDER BY units.rank asc, ranks.rank asc';
It appears to me that the Order by here does not affect the Group_Concat, so my guess is I need to Order the Group_Concat somehow before it goes into an array. The array seems to order it by person id.
Any help would be greatly appreciated. Thanks in advance.