ok, so the part that is causing the loop of the same last logo/name is this:
foreach ($channels as $name) {
$live[$name] = null;
$chanlogo = "https://api.twitch.tv/kraken/channels/$name";
$chandata = file_get_contents($chanlogo);
$result = json_decode($chandata);
$offlogo = $result->logo;
$oname = $result->display_name;
}
But in order to have the offline display names and logo’s I need to use that api from /channels not /streams, is there a way to break this up so it isn’t looping like it is now and pulling the same thing for all channels on the list?
This is the full code:
<?php
$live = array();
$channels = array("channel1", "channel2", "channel3",);
$streamdata = json_decode(@file_get_contents("https://api.twitch.tv/kraken/streams?channel=".implode(",",$channels)), true);
foreach ($channels as $name) {
$live[$name] = null;
$chanlogo = "https://api.twitch.tv/kraken/channels/$name";
$chandata = file_get_contents($chanlogo);
$result = json_decode($chandata);
$offlogo = $result->logo;
$oname = $result->display_name;
}
foreach ($streamdata["streams"] as $stream) {
$live[$stream["channel"]["name"]] = $stream;
}
foreach ($live as $name => $stream) {
if($stream != null){
$dname = $stream['channel']['display_name'];
$game = $stream['game'];
$logo = $stream['channel']['logo'];
$viewers = $stream['viewers'];
echo "<p><img src='$logo' height='45' width='45' style='z-index: 5;float:left;PADDING-RIGHT: 3px;PADDING-LEFT: 3px;'><a href='http://twitch.tv/$name/embed' target='tbox'><font style='font-size: 1rem;line-height: 1.4;white-space: nowrap;font-weight: 700;color: #B9A3E3;text-decoration: none;font-family: 'Open Sans',sans-serif;'>$dname</font></a><br><font style='font-size: 0.75rem;line-height: 1;white-space: nowrap;font-weight: 700;color: #3366FF;text-decoration: none;font-family: 'Open Sans',sans-serif;'>Playing: <img src='online.png' height='7' width='7'> $game<br>Viewers: $viewers</font></p>";
} else{
echo "<p><img src='$offlogo' height='45' width='45' style='z-index: 5; float:left;PADDING-RIGHT: 3px;PADDING-LEFT: 3px;'><a href='http://twitch.tv/$name/embed' target='tbox'><font style='font-size: 1rem;line-height: 1.4;white-space: nowrap;font-weight: 700;color: #B9A3E3;text-decoration: none;font-family: 'Open Sans',sans-serif;'>$oname</font></a><br><font style='font-size: 0.75rem;line-height: 1;white-space: nowrap;font-weight: 700;color: #3366FF;text-decoration: none;font-family: 'Open Sans',sans-serif;'>Playing: <img src='offline.png' height='7' width='7'> Offline<br><br></font></p>";
}
}
?>