- <tr>', ($participant->valide ? '<th></th>' : ''), '<th>Votes</th><th>Jeux</th></tr>';\r
-\r
-$jeux_query = mysql_query("\r
- SELECT jeux.id, jeux.nom, jeux_choisis.participant_id, COUNT(*) + IF(participant_id is not null, 1, 0) - 1 AS nb_vote\r
- FROM jeux LEFT JOIN jeux_choisis ON jeux.id = jeux_choisis.jeu_id\r
- GROUP BY jeux.id\r
- ORDER BY nb_vote DESC, nom \r
+ <tr>', ($participant->existe() ? '<th></th>' : ''), '<th>Votes</th><th>Jeux</th></tr>';\r
+
+# /!\ Attention, requête un poil tricky :
+# On souhait avoir une liste des jeux joués avec pour chaque tuple :
+# - l'id du jeu et son nom
+# - Un tableau des participants ayant voté pour ce jeu
+# De plus il faut que le résultat soit trié par le nombre de vote\r
+$jeux_query = pg_query("\r
+ SELECT
+ jeux.id,
+ jeux.nom,
+ array_agg(jeux_choisis.participant_id) AS participants,
+ (COUNT(*) + (CASE WHEN bool_and(jeux_choisis.participant_id is null) THEN -1 ELSE 0 END)) as nb_vote
+ FROM
+ jeux
+ LEFT JOIN jeux_choisis ON jeux.id = jeux_choisis.jeu_id
+ GROUP BY jeux.id, jeux.nom
+ ORDER BY nb_vote DESC, jeux.nom\r