0 Replies Latest reply on May 9, 2013 9:06 AM by rbmediamonkey

    Incrementing Dynamic JSON Data (updated)

    rbmediamonkey

      Hi,

       

      Hope someone can help, I am currently working on an advertisment banner which scrolls through different messages which are retreived randomly from a PHP file in JSON format.

       

      Some of the messages are directly in the PHP file, however a couple of others the content comes from external urls.

       

      Now from the spec i've been given for one of the values provided by one of the external urls it has to increment every second by a specified value.

       

      Now I've got the increment working via javascript in a separate PHP file, but when I move the code to the JSON formatted file it fails and messages dont appear as they did before.

       

      I do assume this is because the JSON file is only linking to the Adobe Edge HTML5 file retreiving the required data and not processing the JSON file properly i.e. if you were to visit the page directly.

       

      I have tried copying the javascript to a .js file and linking that in the head of the HTML5 file but again it doesn't seem to get picked up?

       

      Just wondering if anyone might know a good way to go about this? I am trying to figure a way to code this in Adobe Edge but because the messages are randomised from the JSON file I guess it will be hard to hook into them to determine which message requires in increment coding.

       

      UPDATE - CODING ADDED

       

      Apologies for not adding it in before but here's my coding:

       

      I have this file (ajax.php) which holds all the content

       

      <?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:

       

              $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'];

       

              echo json_encode('<h2>Bad Beat Jackpot</h2> &pound;' . $initial);

       

              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;

      }

      ?>

       

      This file is then read by my Adobe Edge code (below):

       

      // insert code to be run when the symbol is created here

      $.ajax({

          url: 'ajax.php',

          dataType: 'json',

          success: function(data) {

              sym.$("PlaceholderONE").html(data);

          }

      });

       

      $.ajax({

          url: 'ajax.php',

          dataType: 'json',

          success: function(data) {

              sym.$("PlaceholderTWO").html(data);

          }

      });

       

      $.ajax({

          url: 'ajax.php',

          dataType: 'json',

          success: function(data) {

              sym.$("PlaceholderTHREE").html(data);

          }

      });

       

      Which when published, looks like this:

       

      http://www.manninmedia.co.im/micro/logo-test.html

       

      All looks and animates well, but I need the Bad Beat Jackpot value imported within case 2 in (ajax.php), I need it to increment every second like this:

       

      http://www.manninmedia.co.im/micro/counter2.php

       

      I have it working separately in my (counter2.php) file with some javascript:

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml">

       

      <head>

      <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

      <title>Untitled 1</title>

      </head>

       

      <body onload="incrementNumber()">

       

      <?php

       

      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;

       

               }

       

      }

       

       

              $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>

       

              var number = <?php echo $initial ?>  // put your initial value here

       

              function incrementNumber() {

                  number += <?php echo $increment ?> // you can increment by anything you like here

                  var result=Math.round(number)

                  document.getElementById('counter').innerHTML = result;

              }

       

              // this will run incrementNumber() every second (interval is in ms)

              setInterval(incrementNumber, 1000);

       

              </script>

       

              <?php echo json_encode('<h2 style="float:left">Bad Beat Jackpot</h2> &pound;'); echo '<span id="counter"></span>'; ?>

       

       

       

      </body>

       

      </html>

       

      I wish to combine the two so the Bad Beat Jackpot value increments on the animated banner, however all my efforts have been in vain.

       

      I have thought about applying the increment animation in adobe edge somehow, but how could I hook into case 2 in ajax.php??

       

      Can anyone please help me?

       

       

      Thanks