hi there,
i dont know whether this is more of a php issue or javascript issue but I would appreciate if someone could put me out of my misery as i’ve been on this for days.
basically i have a php file using a switch statement to randomly choose from a list of messages to display on an online web banner:
[url]http://www.manninmedia.co.im/micro/frame-test.html
all the messages work as they should, however on the second message (case 2) required a little extra javascript coding (via a php include of my bbjackpot.php) to apply an increment to a dynamic value.
now because the messages are chosen randomly at every load, occasionally messages will get displayed twice once after the other.
now thats no problem, but with the second message it doesnt execute the javascript in bbjackpot.php a second time and therefore the message turns up blank??
i am getting pretty desperate with this and appreciate anyones help, my code is below:
ajax.php
[code=php]<?php
$num = rand (1,5);
class XmlToJson {
public function Parse ($url) {
$fileContents= file_get_contents($url);
$fileContents = str_replace(array(“n”, “r”, “t”), ”, $fileContents);
$fileContents = trim(str_replace(‘”‘, “‘”, $fileContents));
$simpleXml = simplexml_load_string($fileContents);
$json = json_encode($simpleXml);
return $json;
}
}
switch ($num)
{
case 1:
$jsone = XmlToJson::Parse(“http://www.microgaming.co.uk/pokerfeeds/WebServiceViewOnline.asmx/ViewOnlineXML”);
$jsond = json_decode($jsone, true);
$totalPlayers = $jsond[‘GLOBAL’][‘@attributes’][‘totalPlayers’];
$filledSeats = $jsond[‘GLOBAL’][‘@attributes’][‘filledSeats’];
echo json_encode(‘<h2>Total Player Count</h2> ‘ . $totalPlayers . ‘ Players Online’);
break;
case 2:
ob_start();
include ‘bbjackpot.php’;
$view = ob_get_clean();
echo json_encode(”. $view);
break;
case 3:
echo json_encode(‘<h2>The first online poker network</h2> to offer real play poker on Android mobile devices.’);
break;
case 4:
echo json_encode(‘<h2>The first online poker network</h2> to offer a fast-fold poker variant, Blaze.’);
break;
case 5:
echo json_encode(‘<h2>The first online poker network</h2> management board, created in 2011.’);
break;
}
?>
bbjackpot.php
[code=php]<?php
$jsone = XmlToJson::Parse(“https://mppv2valueadds3.valueactive.eu/MPP_BadBeatFeed/default.aspx”);
$jsond = json_decode($jsone, true);
$name = $jsond[‘data’][‘struct’][‘var’][‘@attributes’][‘name’];
$initial = $jsond[‘data’][‘struct’][‘var’][‘struct’][‘var’][0][‘number’];
$increment = $jsond[‘data’][‘struct’][‘var’][‘struct’][‘var’][1][‘number’]; ?>
<script>
function formatDollar(num) {
var p = (num / 100).toFixed(2).split(“.”);
return “£” + p[0].split(“”).reverse().reduce(function(acc, num, i, orig) {
return num + (i && !(i % 3) ? “,” : “”) + acc;
}, “”) + “.” + p[1];
}
var total = <?php echo $initial ?> // put your initial value here
var addition = Math.round(<?php echo $increment ?>);
function incrementNumber() {
var result = total += addition// you can increment by anything you like here
var jackpot = formatDollar(result);
document.getElementById(‘counter’).innerHTML = jackpot;
}
// this will run incrementNumber() every second (interval is in ms)
setInterval(incrementNumber, 1000);
</script>
<?php echo ‘<h2>Bad Beat Jackpot</h2>’; ?>
<?php echo ‘<span id=”counter”></span>’; ?>