Проблемът е следният: Имам ето този код:
И искам да го направя да подрежда информацията само когато даден стрийм е онлай. Защото страницата зарежда много бавно докато прави проверката, дали даден стрийм е онлайн/оффлайн. Ако някои знае как да го направя моля да пише тук в темата, но ако може малко по-подробно или да даде уроче как стават нещата.
Ето демо на страницата: http://www.leagueofbulgaria.eu/streams
Код:
<?
include 'config.php';
$select = mysql_query("SELECT * FROM streems WHERE featured IN ('0') DESC LIMIT 10")or die(mysql_error());
$num = mysql_num_rows($select);
for ($i=0;$i<$num;$i++) {
$channeldb = mysql_result($select, $i, "channel");
$channel = "$channeldb";
$json_file = @file_get_contents("http://api.justin.tv/api/stream/list.json?channel={$channel}", 0, null, null);
$json_array = json_decode($json_file, true);
$streamData = json_decode(file_get_contents("http://api.justin.tv/api/stream/summary.json?channel={$channel}"),true);
if( array_key_exists( '0', $json_array )
&& array_key_exists( 'channel', $json_array[0] )
&& $json_array[0]['name'] == "live_user_{$channel}" )
{
$channelTitle = $json_array[0]['channel']['title'];
$title = $json_array[0]['channel']['status'];
$views = $streamData['viewers_count'];
echo'
<img class="cAvatar cAvatar-Large" src="http://static-cdn.jtvnw.net/previews/live_user_'.$channelTitle.'-88x88.jpg" border="0" alt="'.$channelTitle.'" style="max-width: 100%; height: auto; background-image: none; width: 64px; float: left;" /></a><a href="/stream?channel='.$channelTitle.'" style="color: #1078b9; -webkit-transition: background-color 0.2s linear, color 0.2s linear; text-decoration: initial; -webkit-transform: translateZ(0px);"><strong style="color: #2f3336;">'.$channelTitle.'</strong></a></h3><a href="/stream?channel='.$channelTitle.'" style="color: #1078b9; -webkit-transition: background-color 0.2s linear, color 0.2s linear; text-decoration: initial; -webkit-transform: translateZ(0px);"><strong style="color: rgba(0, 0, 0, 0.4);">'.$title.'</strong></a></h3><a href="" style="color: rgb(204, 213, 69); -webkit-transition: background-color 0.2s linear, color 0.2s linear; text-decoration: initial; -webkit-transform: translateZ(0px);">'.$views.'</a></strong></span>
<br />';
}
else
{
printf('');
}
}
?>
Ето демо на страницата: http://www.leagueofbulgaria.eu/streams