https://openclassrooms.com/forum/sujet/requete-sql-complexe-ab5a2
Last active
July 28, 2023 09:22
-
-
Save julp/e3ef79aaec837252fb4c2dbb0431adfb to your computer and use it in GitHub Desktop.
[OC] Requête SQL complexe (4 jointures LEFT sur la même table)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$stmt = $bdd->query(<<<'EOS' | |
SELECT | |
ds.sejour_nom, | |
ds.id, | |
ii1.nom, | |
ii2.nom, | |
ii3.nom, | |
ii4.nom | |
FROM tournee_sejour ts | |
LEFT JOIN doc_sejour ds ON ts.id_sejour = ds.id | |
LEFT JOIN index_institutions ii1 ON ts.arret_1 = ii1.id_institution | |
LEFT JOIN index_institutions ii2 ON ts.arret_2 = ii2.id_institution | |
LEFT JOIN index_institutions ii3 ON ts.arret_3 = ii3.id_institution | |
LEFT JOIN index_institutions ii4 ON ts.arret_4 = ii4.id_institution | |
WHERE ds.sejour_actif = 1 | |
EOS | |
); | |
?> | |
<table> | |
<?php while ($donnees = $reponse->fetch(PDO::FETCH_NAMED)): ?> | |
<tr> | |
<td> | |
<?= htmlspecialchars($donnees['sejour_nom']) ?> | |
</td> | |
<?php for ($i = 0; $i < 4; $i++): ?> | |
<td> | |
<?= htmlspecialchars(null === $donnees['nom'][$i] ? '-' : $donnees['nom'][$i]) ?> | |
</td> | |
<?php endfor ?> | |
</tr> | |
<?php endwhile ?> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment