Hello,
I please to some help.
I would display the casting of TV series.
He is my code:
$cast = []; // Associative array [character => [actor]]
while ($row = $castResult->fetch_assoc()) {
// Grouping actors by characters
$cast[$row['charName']][] = $row['personName'];
}
foreach ($cast as $char => $persons) {
echo implode(' > ', $persons), " : {$char}<br>";
}
Here is my sql query:
$castQuery = $conn->prepare('SELECT S.seriesId, CP.characterId AS charId, P.personId, seriesTitle, characterName AS charName, personName, appearanceOrder AS appOrder, period FROM CASTING AS C
JOIN SERIES AS S ON S.seriesId = C.seriesId
JOIN PERSON AS P ON P.personId = C.personId
JOIN CHAR_PLAYED AS CP ON CP.characterId = C.characterId
WHERE S.seriesId = '.$_GET['series'].'
ORDER BY appearanceOrder');
$castQuery->execute();
$castResult = $castQuery->get_result();
This displays the following:
Actor 1 : Character 1
Actor 2 replaced by Actor 2 replaced by … : Character 2 (if an actor is replaced by one or more others
…
Actor 10 : Character 10
If a series has two or more periods, the cast should display like this.
I can’t figure out how to bring that to work.