[RESOLU] Array to string conversion

Eléphanteau du PHP | 10 Messages

06 juin 2024, 09:55

Bonsoir,

Toujours pour mon site series TV.

Je ne parviens toujours pas à afficher correctement la liste des épisodes. Le numéro de saison ne d'affiche pas.
L'affichage devrait être :

Code : Tout sélectionner

1 1x01 Episode 1 Ep SxEp Titre
J'obtiens l'erreur

Code : Tout sélectionner

Warning: Undefined array key "seasonNumber" in /var/www/seriemaniacs/series/episodes.php on line 19
Voici le code qui doit afficher les épisodes :

Code : Tout sélectionner

<?php $seasonList = getSeasonNumber(); $episodeList = getEpisodes(); $seriesIdTest = getPageOnError(); if((isset($_GET['series'])) && ($_GET['series'] > 0) && ($_GET['series'] == $seriesIdTest)) { // If string is not empty then first test if string match the selection $seriesIdTest = $_GET['series']; } else { // If the test fails, return to greating page header("Location: accueil.php"); ob_clean(); die(); } ?> <!-- EPISODES SECTION DISPLAY --> <div class="castAndCrew"> <h2>EPISODES</h2> <?php foreach ($episodeList as $episodes) { echo $episodes['epNumber']."|".$seasonList['seasonNumber']." x ".$episodes['seasonEpNumber']."|".$episodes['episodeTitle']; } ?> </div>
Et les requêtes :

Code : Tout sélectionner

<?php if(isset($_GET['series'])) { $seriesId = $_GET['series']; } if(isset($_GET['episodes'])) { $seriesId = $_GET['episodes']; } if(isset($_GET['letter'])) { $letter = $_GET['letter']; } function getPageOnError() { global $pdo; global $seriesId; $sql = <<<SQL SELECT seriesId FROM SERIES WHERE seriesId = :seriesId SQL; $idQuery = $pdo->prepare($sql); $idQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $idQuery->execute(); $row = $idQuery->fetch(); $seriesIdTest = $row['seriesId']; return $seriesIdTest; } function getLetter() { global $pdo; global $letter; return $letter; } function getSeriesList() { global $pdo; global $letter; // Getting the series list from first letter $sql = <<<SQL SELECT titleSort, seriesTitle, seriesId, releaseYear FROM SORTLIST WHERE titleSort RLIKE '^[$letter]' ORDER BY titleSort, releaseYear SQL; $query = $pdo->prepare($sql); $query->execute(); $seriesList = []; while (($row = $query->fetch())) { $seriesList = [ 'seriesTitle' => $row['seriesTitle'], 'releaseYear' => $row['releaseYear'], 'seriesId' => $row['seriesId'], ]; $seriesLists[] = $seriesList; } return $seriesLists; } function getPoster() { global $pdo; global $seriesId; // Getting the series poster, if any $sql = <<<SQL SELECT seriesTitle, seriesPoster FROM SERIES WHERE seriesId = :seriesId SQL; $imageQuery = $pdo->prepare($sql); $imageQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $imageQuery->execute(); $row = $imageQuery->fetch(); $seriesPoster = $row['seriesPoster']; return $seriesPoster; } function getTitle() { global $pdo; global $seriesId; // Getting the series title $sql = <<<SQL SELECT S.seriesId AS seriesId, SL.seriesTitle AS frenchTitle, S.seriesTitle AS seriesTitle FROM SERIESLIST AS SL LEFT JOIN SERIES AS S ON S.seriesId = SL.seriesId WHERE SL.seriesId = :seriesId SQL; $titleQuery = $pdo->prepare($sql); $titleQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $titleQuery->execute(); $row = $titleQuery->fetch(); if ($row['frenchTitle'] == $row['seriesTitle']) { // Test if The original an french titles are the same $title = mb_strtoupper($row['frenchTitle']); // If they are the same display only one uppercase title } else { // If they're different, display the french title uppercase and the original one lowercase $title = mb_strtoupper($row['frenchTitle'])." (".$row['seriesTitle'].")"; $limit = "40"; if(strlen($title) <= $limit) { // Test String Lenght $title = mb_strtoupper($row['frenchTitle'])." (".$row['seriesTitle'].")"; // If the lenght is smaller then limit } else { // If lenght is bigger, display the title on 2 lines $title = mb_strtoupper($row['frenchTitle'])."<br>(".$row['seriesTitle'].")"; } } $titles = [ 'pageTitle' => $row['frenchTitle'], 'title' => $title, 'seriesId' => $row['seriesId'], ]; return $titles; } function getSpinOff() { // Getting the Spin-Off if any global $pdo; if(isset($_GET['series'])) { $seriesId = $_GET['series']; } $sql = <<<SQL SELECT S.seriesId FROM SERIES AS S JOIN SPINOFF AS SO ON SO.seriesId_spinOff = S.seriesId WHERE S.seriesId = :seriesId AND SO.seriesId_spinOff = S.seriesId SQL; $isSpinOffQuery = $pdo->prepare($sql); $isSpinOffQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $isSpinOffQuery->execute(); $row = $isSpinOffQuery->fetch(); if (isset($row['seriesId'] )) { // Test if the series is a Spin-Off // Getting the prequel from Query $sql = <<<SQL SELECT PL.seriesTitle AS prequel, S.seriesTitle AS spinOff FROM SPINOFF AS SO JOIN SERIESLIST AS PL ON PL.seriesId = SO.seriesId_prequel JOIN SERIESLIST AS S ON S.seriesId = SO.seriesId_spinOff WHERE S.seriesId = :seriesId SQL; $spinOffQuery = $pdo->prepare($sql); $spinOffQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $spinOffQuery->execute(); $row = $spinOffQuery->fetch(); $prequel = $row['prequel']; } else { $prequel = 0; } return $prequel; } function getCompany() { global $pdo; global $seriesId; // Get the Company Name if any $sql = <<<SQL SELECT companyName AS companyName FROM COMPANY AS C LEFT JOIN PRODUCTION AS P ON P.companyId = C.companyId LEFT JOIN SERIES AS S ON S.seriesId = P.seriesId WHERE S.seriesId = :seriesId SQL; $companyQuery = $pdo->prepare($sql); $companyQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $companyQuery->execute(); $rows = $companyQuery->fetchAll(); if(isset($rows[0]['companyName'])) { $companyName = []; foreach ($rows as $row) { $companyName = [ 'companyName' => $row['companyName'], ]; $companyNames[] = $companyName; } } else { $companyNames = 0; } return $companyNames; } function getProducer() { global $pdo; global $seriesId; // Getting the Producer Name if any $sql = <<<SQL SELECT personName AS personName FROM PERSON AS P LEFT JOIN CREW AS C ON C.personId = P.personId LEFT JOIN ROLE AS R ON R.roleId = C.roleId LEFT JOIN SERIES AS S ON S.seriesId = C.seriesId WHERE S.seriesId = :seriesId AND R.roleId = 1 SQL; $producerQuery = $pdo->prepare($sql); $producerQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $producerQuery->execute(); $rows = $producerQuery->fetchAll(); if(isset($rows[0]['personName'])) { $producerName = []; foreach ($rows as $row) { $producerName = [ 'producerName' => $row['personName'], ]; $producerNames[] = $producerName; } } else { $producerNames = 0; } return $producerNames; } function getExecProducer() { global $pdo; global $seriesId; // Getting the Executive Producer Name if any $sql = <<<SQL SELECT personName AS personName FROM PERSON AS P LEFT JOIN CREW AS C ON C.personId = P.personId LEFT JOIN ROLE AS R ON R.roleId = C.roleId LEFT JOIN SERIES AS S ON S.seriesId = C.seriesId WHERE S.seriesId = :seriesId AND R.roleId = 2 SQL; $execProducerQuery = $pdo->prepare($sql); $execProducerQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $execProducerQuery->execute(); $rows = $execProducerQuery->fetchAll(); if(isset($rows[0]['personName'])) { $execProducerName = []; foreach ($rows as $row) { $execProducerName = [ 'execProducerName' => $row['personName'], ]; $execProducerNames[] = $execProducerName; } } else { $execProducerNames = 0; } return $execProducerNames; } function getDirector() { global $pdo; global $seriesId; // Getting the Director Name if any $sql = <<<SQL SELECT personName AS personName FROM PERSON AS P LEFT JOIN CREW AS C ON C.personId = P.personId LEFT JOIN ROLE AS R ON R.roleId = C.roleId LEFT JOIN SERIES AS S ON S.seriesId = C.seriesId WHERE S.seriesId = :seriesId AND R.roleId = 3 SQL; $directorQuery = $pdo->prepare($sql); $directorQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $directorQuery->execute(); $rows = $directorQuery->fetchAll(); if(isset($rows[0]['personName'])) { $directorName = []; foreach ($rows as $row) { $directorName = [ 'directorName' => $row['personName'], ]; $directorNames[] = $directorName; } } else { $directorNames = 0; } return $directorNames; } function getCreator() { global $pdo; global $seriesId; // Getting the Creator Name if any $crSql = <<<SQL SELECT personName AS personName FROM PERSON AS P LEFT JOIN CREW AS C ON C.personId = P.personId LEFT JOIN ROLE AS R ON R.roleId = C.roleId LEFT JOIN SERIES AS S ON S.seriesId = C.seriesId WHERE S.seriesId = :seriesId AND R.roleId = 5 SQL; $creatorQuery = $pdo->prepare($crSql); $creatorQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $creatorQuery->execute(); $rows = $creatorQuery->fetchAll(); if(isset($rows[0]['personName'])) { $creator = []; foreach ($rows as $row) { $creator = [ 'creatorName' => $row['personName'], ]; $creators[] = $creator; } } else { $creators = 0; } return $creators; } function getOrigCreator() { global $pdo; global $seriesId; // Getting the Original Creator Name if any $ocSql = <<<SQL SELECT originalText AS origText FROM ORIG_CREATION AS OC LEFT JOIN SERIES AS S ON S.originalId = OC.originalId WHERE S.seriesId = :seriesId SQL; $origCreatorQuery = $pdo->prepare($ocSql); $origCreatorQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $origCreatorQuery->execute(); $rows = $origCreatorQuery->fetchAll(); if(isset($rows[0]['origText'])) { $origCreator = []; foreach ($rows as $row) { $origCreator = [ 'origCreator' => $row['origText'], ]; $origCreators[] = $origCreator; } } else { $origCreators = 0; } return $origCreators; } function getCast() { global $pdo; global $seriesId; // Getting Cast List $sql = <<<SQL SELECT S.seriesId, CP.characterId AS charId, P.personId, seriesTitle, characterName AS charName, personName, appearanceOrder AS appOrder, period, periodNumber AS periodNum 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 = :seriesId ORDER BY periodNum, appOrder SQL; $castQuery = $pdo->prepare($sql); $castQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $castQuery->execute(); $rows = $castQuery->fetchAll(); $cast = []; foreach ($rows as $row) { $cast = [ 'period' => $row['period'], 'charName' => $row['charName'], 'personName' => $row['personName'], ]; $castList[] = $cast; } return $castList; } function getFirstAired() { global $pdo; global $seriesId; // Getting the series language $sql = <<<SQL SELECT S.seriesId FROM SERIES AS S JOIN FRENCH_SERIES AS F ON F.seriesId = S.seriesId WHERE S.seriesId = :seriesId AND F.seriesId = S.seriesId SQL; $isFrenchQuery = $pdo->prepare($sql); $isFrenchQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $isFrenchQuery->execute(); $row = $isFrenchQuery->fetch(); // Gettings first aired channel and year $sql = <<<SQL SELECT countryName, releaseYear, frenchReleaseYear, channelName, frenchChannelName FROM FIRSTAIRED WHERE seriesId = :seriesId SQL; $airedQuery = $pdo->prepare($sql); $airedQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $airedQuery->execute(); if (isset($row['seriesId'] )) { // Test if it's a french series $firstAired = []; $row = $airedQuery->fetch(); $firstAired = [ 'countryName' => 'France', 'channelName' => $row['channelName'], 'releaseYear' => $row['releaseYear'], ]; $firstAiredInfos[] = $firstAired; return $firstAiredInfos; } else { $firstAired = []; $row = $airedQuery->fetch(); $firstAired = [ 'countryName' => $row['countryName'], 'channelName' => $row['channelName'], 'releaseYear' => $row['releaseYear'], 'frenchChannelName' => $row['frenchChannelName'], 'frenchReleaseYear' => $row['frenchReleaseYear'], ]; $firstAiredInfos[] = $firstAired; return $firstAiredInfos; } } function getSeasonNumber() { global $pdo; global $seriesId; // Getting Season Number $sql = <<<SQL SELECT S.seriesId, SN.seasonId, SN.seasonNumber, E.seasonId FROM SEASON AS SN JOIN EPISODE AS E ON E.seasonId = SN.seasonId JOIN SERIES AS S ON S.seriesId = E.seriesId WHERE S.seriesId = :seriesId ORDER BY SN.seasonId SQL; $seasonQuery = $pdo->prepare($sql); $seasonQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $seasonQuery->execute(); $rows = $seasonQuery->fetchAll(); $season = []; foreach ($rows as $row) { $season = [ 'seasonNumber' => $row['seasonNumber'], ]; $seasonList[] = $season; } return $seasonList; } function getEpisodes() { global $pdo; global $seriesId; // Getting Episodes List $sql = <<<SQL SELECT S.seriesId, E.episodeId AS epId, E.episodeNumber, E.seasonEpisodeNumber, E.episodeTitle, SN.seasonId AS seasonId, SN.seasonNumber as SeasonNumber FROM EPISODE AS E JOIN SERIES AS S ON S.seriesId = E.seriesId JOIN SEASON AS SN ON SN.seasonId = E.seasonId WHERE S.seriesId = :seriesId ORDER BY episodeNumber, seasonEpisodeNumber SQL; $episodesQuery = $pdo->prepare($sql); $episodesQuery->bindParam(':seriesId', $seriesId, PDO::PARAM_INT); $episodesQuery->execute(); $rows = $episodesQuery->fetchAll(); $episode = []; foreach ($rows as $row) { $episode = [ 'epNumber' => $row['episodeNumber'], 'seasonEpNumber' => $row['seasonEpisodeNumber'], 'episodeTitle' => $row['episodeTitle'], ]; $episodeList[] = $episode; } return $episodeList; } ?>
Un petit coup de main serait bien utile.

Mammouth du PHP | 1967 Messages

06 juin 2024, 12:52

affiche le contenu de ton tableau avec var_dump();
et vérifie bien la casse !!

EDIT
Ah ben non en plus de ton problème de casse, tu ne récupère même pas tous ce que ta requète te fourni dans ta fonction getEpisode()
Spols
pour les fan de rubik's cube ou pour les curieux ==> le portail francophone du rubik's cube

Mammouth du PHP | 2703 Messages

06 juin 2024, 14:20

vu la structure de $seasonList, $seasonList['seasonNumber'] n'existe pas.
$seasonList[0]['seasonNumber'] ne générera pas d'erreur si la requête retourne bien au moins un résultat.

c'est horrible que la fonction getEpisodes ne prenne pas un paramètre avec l'id de série.

Eléphanteau du PHP | 10 Messages

06 juin 2024, 16:46

Bonjour,

Tout d'abord merci de m'avoir fait remarquer le problème de casse.

Ensuite un merci pour le coup de main. Avec '$seasonList[0]['seasonNumber']' les épisodes s'affichent parfaitement.
vu la structure de $seasonList, $seasonList['seasonNumber'] n'existe pas.
Je ne comprends pas pourquoi seasonNumber n'existe pas, puisqu'il est fournit par la requête de la fonction getEpisodes().

Mammouth du PHP | 2703 Messages

06 juin 2024, 17:12

faire un var_dump de la variable. c'est un tableau de tableau.

c'est horrible que la fonction getEpisodes ne prenne pas un paramètre avec l'id de série.

Eléphanteau du PHP | 10 Messages

07 juin 2024, 10:38

En fait, je me rends compte que la fonction getSeasonNumber() est parfaitement superflue, voir même incorrecte. De cette façon, le numéro de saison est répéée d'une saison à l'autre.

En fait, je récupère déjà sesaonNumber dans la requête de la fonction getEpisodes'), ce qui est bien plus correct et logique.