title: Auto Refresh HTML Table every x seconds
body: <p>I am attempting to refresh a table i have as the variables in there are constantly updated and i want to re-update those variable every few seconds. I have already done up code on my part by giving the table an id and creating a div for it. The code will explain what i actually. Thanks in Advance ! Added Var Table ,Var Refresher, table id is tableID . however the code still wont reload my table !Any ideas??</p>
  
  <p>Test.php </p>
  
  <pre><code>        &lt;html&gt;
      &lt;head&gt;
          &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;
          &lt;script type='text/javascript'&gt;
       var table = $('#tableID');
  
      // refresh every 5 seconds
  
  
     //    var refresher = setInterval(function() { table.load("refreshable"); }, 5000);
      var refresher = setInterval(table.load.bind(table, "refreshable.php"), 5000);
      //var refresh = setInterval($("#tableID")).load('refreshable.php'),3000);
  
    setInterval(function() {
        clearInterval(refresher);
      }, 1800000);
  
  
      &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;div id="tableID"&gt;
      &lt;?php include_once'refreshable.php'; ?&gt;
      &lt;/div&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>refreshable.php</p>
  
  <pre><code>&lt;?php
  require_once 'connect.php';
  include 'start.php';
  include 'functions.php';
  header("Cache-Control: no-cache,no-store");
  
  $query = "SELECT * FROM opentrades"; //You don't need a ; like you do in SQL
  $result = mysql_query($query);
  echo "&lt;table border = '1px' &gt;"; // start a table tag in the HTML
  echo "&lt;tr&gt;&lt;td&gt;" . "Order Number" . "&lt;/td&gt;&lt;td&gt;" . "Selection" . "&lt;/td&gt;&lt;td&gt;" . "Date" . "&lt;/td&gt;&lt;td&gt;" . "Type" . "&lt;/td&gt;&lt;td&gt;" . "Size" . "&lt;/td&gt;&lt;td&gt;" . "Bid Price" . "&lt;/td&gt;&lt;td&gt;" . "Offer Price" . "&lt;/td&gt;&lt;td&gt;" ."Stop Loss" . "&lt;/td&gt;&lt;td&gt;" . "Take Profit" . "&lt;/td&gt;&lt;td&gt;" ."Profit/Loss(USD)"."&lt;/td&gt;&lt;td&gt;" ."Close"."&lt;/td&gt;&lt;/tr&gt;" ;  //$row['index'] the index here is a field name
  
  while($row = mysql_fetch_assoc($result)){   //Creates a loop to loop through results
  if ($row['selection']=='eur/usd')// TO RETRIEVE BID AND OFFER FOR EACH ROW
        {
        $bidpricepl=$bid;
  
        $offerpricepl=$bid1;
  
        }
    elseif ($row['selection']=='usd/jpy')
        {
        $bidpricepl=$bid2;
  
        $offerpricepl=$bid3;
  
        }
    elseif ($row['selection']=='usd/cad')
        {
        $bidpricepl=$bid4;
  
        $offerpricepl=$bid5;
  
        }
    elseif ($row['selection']=='eur/jpy')
        {
        $bidpricepl=$bid6;
  
        $offerpricepl=$bid7;
  
        }
    elseif ($row['selection']=='eur/chf')
        {
        $bidpricepl=$bid8;
  
        $offerpricepl=$bid9;
  
        }
    elseif ($row['selection']=='gbp/usd')
        {
        $bidpricepl=$bid10;
  
        $offerpricepl=$bid11;
  
        }
    elseif ($row['selection']=='aud/usd')
        {
        $bidpricepl=$bid12;
  
        $offerpricepl=$bid13;
  
        }
    elseif ($row['selection']=='usd/chf')
        {
        $bidpricepl=$bid14;
  
        $offerpricepl=$bid15;
  
        }
    if ($row['type']=="buy")
      {
  
        $minipipskiller='10';
        $offeropen=$row['offerprice'];
        $pips=$offerpricepl-$offeropen;
        $closedb=$offeropen;
        $pips1=round($pips, 6);
        $pips2 = str_replace('.', '', $pips1);
          if ($pips2&lt;0)
        {
          $pips2 = str_replace('-', '', $pips2);
          $pips2 = ltrim($pips2, '0');
          $pips2 = -1 * abs($pips2);
        }
        else {
          $pips2 = ltrim($pips2, '0');
        }
        $pips3=$pips2/$minipipskiller;
      }// PIP COUNTING
    elseif ($row['type']=="sell")//FOR PIP COUNTING
      {
  
        $minipipskiller='10';
        $bidopen=$row['bidprice'];
        $pips=$bidopen-$bidpricepl;
        $closedb=$bidopen;
        $pips1=round($pips, 6);
        $pips2 = str_replace('.', '', $pips1);
        if ($pips2&lt;0)
        {
          $pips2 = str_replace('-', '', $pips2);
          $pips2 = ltrim($pips2, '0');
          $pips2 = -1 * abs($pips2);
        }
        else {
          $pips2 = ltrim($pips2, '0');
        }
        $pips3=$pips2/$minipipskiller;
      }
  
  
  
        $ticksize= "0.0001";// FOR PROFIT AND LOSS
        $lot1 = "100000";
        $sizecalc=$row['size'] * $lot1;
  
          if ($row['type']=="buy")
        { 
          $profitandloss=$sizecalc*$ticksize*$pips3; //per TRADE
        }
        if ($row['type']=="sell")
        {
          $profitandloss=$sizecalc*$ticksize*$pips3; //per TRADE
        }
  
        $zero= '0';
  
        if($profitandloss&lt;$zero) {
              $profitText = "&lt;div style=\"color: red;\"&gt;$profitandloss&lt;/div&gt;";
          } elseif ($profitandloss&gt;$zero) {
              $profitText = "&lt;div style=\"color: green;\"&gt;$profitandloss&lt;/div&gt;";
          }
  
  
  $sum+= $profitandloss;
  
  
      echo "&lt;tr&gt;&lt;td&gt;" . $row['trade_id'] .         
          "&lt;/td&gt;&lt;td&gt;" . $row['selection'] . 
          "&lt;/td&gt;&lt;td&gt;" . $row['date'] .
          "&lt;/td&gt;&lt;td&gt;" . $row['type'] .
          "&lt;/td&gt;&lt;td&gt;" . $row['size'] .
          "&lt;/td&gt;&lt;td&gt;" . $row['bidprice'] .
          "&lt;/td&gt;&lt;td&gt;" . $row['offerprice'] .
          "&lt;/td&gt;&lt;td&gt;" . $row['stoploss'] .
          "&lt;/td&gt;&lt;td&gt;" . $row['takeprofit'] .
          "&lt;/td&gt;&lt;td&gt;" . $profitText . 
          "&lt;/td&gt;&lt;td&gt;&lt;a href ='delete.php?id=".
          $row['trade_id']."'&gt;X&lt;/a&gt;
         &lt;/td&gt;&lt;/tr&gt;";  
  $profitandloss=0;
  
  if($sum&lt;$zero) {
      $sumText = "&lt;div style=\"color: red;\"&gt;$sum&lt;/div&gt;";
  } elseif ($sum&gt;$zero) {
      $sumText = "&lt;div style=\"color: green;\"&gt;$sum&lt;/div&gt;";
  }
  }
  
  echo "&lt;/table&gt;&lt;br&gt;";
  
  
  
  ?&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/KiuWg.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/PpQzW.jpg" alt="enter image description here"></p>