title: Mysql with Set Timeout function, While loop to fetch data with specific time interval
body: <p>I want to fetch data from the database table with specific time interval. Data base is being filled every 5 seconds time so I need to fetch data 5 second intervals.</p>
  
  <p>This is my code without the setTimeout function it displays the whole result up to the value the table is filled, but have to refresh the page to get other data filled after that.</p>
  
  <pre><code>      &lt;?php
          $con = mysql_connect("localhost","shsas","");
  
          if (!$con) {
          die('Could not connect: ' . mysql_error());
                     }
          else
                    {
                    &lt;script type="text/javascript"&gt;
                    mysql_select_db("shsas", $con);
                    $sth = mysql_query("SELECT Gaslevel FROM gas");
                    $rows = array();
                    $rows['name'] = 'Gaslevel';
  
         setTimeout(function(){
  
              while($r = mysql_fetch_array($sth)) {
              $rows['data'][] = $r['Gaslevel'];
              $result = array();
              array_push($result,$rows);
              print json_encode($result, JSON_NUMERIC_CHECK);
  
             },5000);
         }
     &lt;/script&gt;
         }
     mysql_close($con);
  
     ?&gt;
  </code></pre>