tmdb_v3-PHP-API-
tmdb_v3-PHP-API- copied to clipboard
Num of episodes in seasons loop
Hello,
Any idea why the code below in infoTVShow.php return 0 as amount of episodes in seasons loop?
echo '<li>Seasons: <ul>'; $seasons = $tvShow->getSeasons(); foreach ($seasons as $season) { echo '<li><a href="https://www.themoviedb.org/tv/season/'.$season->getID().'">Season '.$season->getSeasonNumber().'</a></li> <li>Air Date: '.$season->getAirDate().'</li> <li>Episodes: '.$season->getNumEpisodes().'</li> <li><img src="'. $tmdb->getImageURL('w185') . $season->getPoster() .'"/></li>'; } echo '</ul></li>
I tried to pass as parameter:
$season->getNumEpisodes($season->getID())
but I had no success.
Thank you Chris
I found a trick to solve this, but I don't think that is a quality code. Added at the top of foreach loop
$season_data = $tmdb->getSeason($tvShow->getID(), $season->getSeasonNumber());
and then:
$season_data->getNumEpisodes()
@ChrisTERiS
Added a getEpisodeCount() to Seasons when you are in a tvShow Scope. Your first solutions would be correct, when you fetch the Season Details but you are coming from tvShow Details. Therefore the season has not all detail information.
Pushed on my fork and created a merge request for that. Also added an example in infoTVShow.php how to iterate over $seasons and display episode count;
Your second solution would work aswell, but this is fetching season details for each.
@ChrisTERiS
Added a getEpisodeCount() to Seasons when you are in a tvShow Scope. Your first solutions would be correct, when you fetch the Season Details but you are coming from tvShow Details. Therefore the season has not all detail information.
Pushed on my fork and created a merge request for that. Also added an example in infoTVShow.php how to iterate over $seasons and display episode count;
Your second solution would work aswell, but this is fetching season details for each.
I really appreciate your help and support. THANK YOU !!