Is there a way to make a certain div autorefresh every minute or so, and not my whole page? Because it would take too long to reload the page every minute. The div itself is the important part which can change.
<div id="livetable">
<?php loadpage(); ?>
</div>
<?php
define('ELEMENT_CONTENT_ONLY', true);
define('ELEMENT_PRESERVE_TAGS', false);
function value_in($element_name, $xml, $content_only = true)
{
if ($xml == false)
{
return false;
}
$found = preg_match('#<'.$element_name.'(?:\s+[^>]+)?>(.*?)'.'</'.$element_name.'>#s', $xml, $matches);
if ($found != false)
{
if ($content_only)
{
return $matches[1]; //ignore the enclosing tags
}
else
{
return $matches[0]; //return the full pattern match
}
}
// No match found: return false.
return false;
}
function loadpage()
{
echo "<table cellpadding=\"0\" cellspacing=\"0\" style=\"width: 95%\" >";
echo "<tr class=\"info-row\" bgcolor=#252525 style=\"color:white; height: 15px;\">";
echo "<td style=\"width: 14%; height: 10px; padding-left: 5px;\"><b>Preview</b></td>";
echo "<td style=\"width: 10%; height: 10px; padding-left: 5px;\"><b>Live</b></td>";
echo "<td style=\"width: 36%; height: 10px; padding-left: 5px;\"><b>Stream</b></td>";
echo "<td style=\"width: 10%; height: 10px; padding-left: 5px;\"><b>Viewers</b></td>";
echo "<td style=\"width: 10%; height: 10px; padding-left: 5px;\"><b>Time online</b></td>";
echo "</tr>";
addrow(107473,10,"Osuryn","Osuryn is streaming random games live",false);
addrow(210320,28,"Dennojj","Dennojj is streaming PS3 games",true);
echo "</table>";
}
function addrow($streamID, $streamPage , $streamName , $streamSlogan, $odd)
{
if ($odd)
{
echo "<tr class=\"content-row online\" id=\"958\" bgcolor=#A7A7A7>";
}
else
{
echo "<tr class=\"content-row online\" id=\"958\" bgcolor=#BFBFBF>";
}
echo "<td style=\"width: 14%;\"><img src=\"http://img.hw.own3d.tv/live/live_tn_".$streamID."_.jpg\" style=\"height: 72px;\" \></td>";
echo "<td style=\"width: 10%; padding-left: 5px;\"><br><br><b>".getLiveStatus($streamID)."</b></td>";
echo "<td style=\"width: 36%; vertical-align: top; padding-top: 6px; padding-right: 6px;\">";
echo "<div><br><a href=\"http://brokendiamond.org/?q=node/$streamPage\">$streamName</a></div>";
echo "<div style=\"padding-top: 6px; font-size: 11px;\">$streamSlogan</div>";
echo "</td>";
echo "<td style=\"width: 10%; padding-left: 5px;\"><br><br>".getLiveViews($streamID)."</td>";
echo "<td style=\"width: 10%; padding-left: 5px;\"><br><br>".getOnTime($streamID)." minutes online</td>";
echo "</tr>";
}
function getLiveStatus($streamID)
{
$request = 'http://api.own3d.tv/liveCheck.php?live_id='.$streamID;
$arg = '240';
$session = curl_init($request.$arg);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
if (preg_match("/true/",$response, $result))
{
$streamStatus="Live";
}
else
{
$streamStatus="Offline";
}
return $streamStatus;
}
function getLiveViews($StreamID)
{
$request = 'http://api.own3d.tv/liveCheck.php?live_id='.$StreamID;
$arg = '240';
$session = curl_init($request.$arg);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
$viewStatus =value_in('liveViewers', $response) + "";
return $viewStatus;
}
function getOnTime($StreamID)
{
$request = 'http://api.own3d.tv/liveCheck.php?live_id='.$StreamID;
$arg = '240';
$session = curl_init($request.$arg);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
$onStatus =value_in('LiveDuration', $response) + "";
return $onStatus;
}
?>
You’ll need to make
AJAXrequest with JavaScript that’ll update thedivor use aniframe.The simplest way to do this or maybe if you’re not familiar with JavaScript, is to use an
iframe. Basically what you need to do is have the content of thedivloaded using theiframeand also modify the PHP code that’s used within theiframeto reload the page after X seconds. This should be easy with PHPheader()function.If you’re going to go with AJAX instead, you’ll want to use the
setInterval()function to repeat a function call that will actually make the AJAX request and update thediv‘s content. However, it might be a good idea to usesetTimeout()instead and have the function call itself, by also usingsetTimeout()too of course after X seconds. The reason for that is because, by usingsetInterval()JavaScript will continues to run even if the last operation has not yet finished. But if you were to usesetTimeout()JavaScript will wait for the last function call to finish before moving on to the next one.