title: Change iFrame SRC and reload iFrame when database content changes
body: <p>I apologise if this has been covered however I couldn't find anything similar enough to help me. </p>
  
  <p>I am basically looking to replace the src of 4 iFrames and reload them when content inside a database changes. I have 2 pages in this scenario. The first page is the controller page which updates the database with the changes. The second page is the view portal that has 4 iFrames in a quad split arrangement. The purpose of the page is to monitor specific sites and I would like to be able to update any one of the 4 iFrames remotely (say from an iPad).</p>
  
  <p>I currently have my database setup. My table has 3 columns (id / name / url).
  I've filled the table with 4 entries so far:<br>
  1 | frame1 | ht*p://www.google.com<br>
  2 | frame2 | ht*p://www.darkhorizons.com<br>
  3 | frame3 | ht*p://www.smh.com.au<br>
  4 | frame4 | ht*p://www.9to5mac.com<br></p>
  
  <p>I would like my viewing portal page (Page2) to constantly check each entry in the db to see if it is different to what it is currently displaying. Something along the lines of: if db-frame1-url is not equal to iframe1.src then iframe1.src equals db-frame1-url. And so on...</p>
  
  <p>I've build most of my site in PHP so far, however I've been told that an AJAX JQuery solution might be best for me here. I'm really not too sure as programming is not one of my strong suits.</p>
  
  <p>Any help at all would be greatly appreciated!</p>
  
  <hr>
  
  <p>AJAX.PHP</p>
  
  <pre><code>&lt;?php
  
  $con=mysqli_connect("localhost","dbuser","dbpass","dbname");
  
  if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
  
  $result = mysqli_query($con,"SELECT * FROM frameContent");
  
  $row = mysqli_fetch_array($result);
  print_r(json_encode($row));
  
  mysqli_close($con);
  
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p>OUTPUT.HTML</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;script src="../assets/scripts/jquery-2.0.3.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/JavaScript"&gt; 
  setInterval(function(){
      $.ajax({
                  url: "ajax.php",
                  type: "GET",
                  data: "",
                  cache: false,
                  success: function(resp) {
                      //
                      try {
                 json = $.parseJSON(resp);
              } catch (error) {
                 json = null;
              }
              //
              if (json) {
                         console.dir(json);
                         $.each(json, function(key,val){
                            if ($("#"+val.name).attr("src") != val.src) {
                              $("#"+val.name).attr("src",val.src);
                            }
                         });
                      }
  
                  }
              });
  },6000);
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;iframe id="frame1" src="http://www.google.com"&gt;&lt;/iframe&gt;
      &lt;iframe id="frame2" src="http://www.darkhorizons.com"&gt;&lt;/iframe&gt;
      &lt;iframe id="frame3" src="http://www.smh.com.au"&gt;&lt;/iframe&gt;
      &lt;iframe id="frame4" src="http://www.9to5mac.com"&gt;&lt;/iframe&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>