title: Multiple Divs refreshing from mysql database
body: <p>I am new to php and ajax and i have been trying to create a real time dashboard which updates from a mysql database without the page refreshing. I have been able to create this in my code below however i am struggling on how to adapt this so it will work with multiple sql queries and different Divs.</p>
  
  <p>Currently my code runs the sql query and outputs to the OrderSubmitted Div ID.  I am wanting to have output another sql query to the div Id Orders Fulfilled how would i go about doing this?</p>
  
  <p>HTML </p>
  
  <pre><code>          &lt;div class="row"&gt;
          &lt;!-- Left Box --&gt;
          &lt;div class="col-lg-6 col-sm-6" style="padding-right:15px; padding-left:0px"&gt;
            &lt;div class="well" style="height: 300px;"&gt;
              &lt;h2 style="text-align:center; font-size:8em;"&gt;
                &lt;div id="SubmittedOrders"&gt;&lt;/div&gt;
              &lt;/h2&gt;
              &lt;p style="text-align:center; font-size:1.5em;"&gt;Outstanding Orders&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;!-- Right Box --&gt;
  
          &lt;div class="col-lg-6 col-sm-6" style="padding-left:15px; padding-right:0px"&gt;
            &lt;div class="well" style="height: 300px;"&gt;
              &lt;h2 style="text-align:center; font-size:8em;"&gt; 
                &lt;div id ="OrderFulfilled"&gt;&lt;/div&gt;
              &lt;/h2&gt;
              &lt;p style="text-align:center; font-size:1.5em;"&gt;Orders fulfiled today&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
  
        &lt;/div&gt;
  </code></pre>
  
  <p>AJAX script</p>
  
  <pre><code>function getOrderStatus() {
  
    ?&gt;
  
      &lt;script&gt;
        // IE5/6 support
  
        function ajax_loop() {
  
          if (window.XMLHttpRequest) {
            xmlhttp=new XMLHttpRequest();
          } else {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
  
          // Create function for handling AJAX response
          // Set dashboard div's contents to the response for Submitted Orders 
          xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) {
              document.getElementById("SubmittedOrders").innerHTML = xmlhttp.responseText;
              setTimeout(ajax_loop, 1000);
            }
          }
  
          // Send AJAX request
          xmlhttp.open("POST","getOrderStatus.php");
          xmlhttp.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
          xmlhttp.send("action=update");
  
        }
  
        ajax_loop();
  
      &lt;/script&gt;  
  
    &lt;?php
  
  }
  </code></pre>
  
  <p>getOrderStatus Php File</p>
  
  <pre><code> &lt;?php
    // Query users table
    $sql = "SELECT COUNT(STATUS) from CE_TRANSACTIONS where STATUS = 0;";
  
  // Execute query 
    $result = mysqli_query( $link, $sql );
  
  // Loop through rows and draw table
  
    while ( $row = mysqli_fetch_assoc($result) ) {
  
       foreach ( $row as $field ) {
          echo "$field";
       }
    }
  </code></pre>