title: How to refresh a page when a certain table gets new rows (PHP)?
body: <p>I've been looking for some script that would refresh my page after it notices a new entry in a specific table of a database. So basically... The script would check in the table every five or so seconds and if it notices anything with the time stamp greater than time() (time of when the page was loaded, obviously, not current time) with an id column value of eg. 14, it would refresh the page.</p>
  
  <p>I looked on line a lot trying to solve this, but I don't seem to find the right answers. You see, the problem is JavaScript and AJAX aren't really that familiar to me.</p>
  
  <p>Sorry if it seems like a stupid question, it really means the world to me right now.
  Other answers are welcome as well... Like how could I do it using Comet or long Sockets?
  Because I'm 100% clueless.</p>
  
  <p>Here is my current (reduced) code of that page:</p>
  
  <pre><code>if (isset($_GET['view'])) {
  $duel_id = mysqli_real_escape_string($query, $_GET['view']);
  $result = mysqli_query($query, "SELECT * FROM duels WHERE `id` = '$duel_id' LIMIT 0, 1") or die(mysqli_error($query));
  $row = mysqli_fetch_array($result);
  if ($row['member_1'] !== $member_id &amp;&amp; $row['member_2'] !== $member_id) {
      echo '&lt;meta http-equiv="refresh" content="0; url=redirect.php" /&gt;';
      exit;
  } else {
      //IRRELEVANT FUNCTIONS
      if ($my_turn == false &amp;&amp; $row['winner'] == 0) {
          //IRRELEVANT FUNCTIONS
      } else {
          echo '&lt;center&gt;&lt;form action="spell.php" method="post"&gt;&lt;table style="margin: 20px;"&gt;';
          //300 LINES OF DYNAMIC FORMS AND INPUTS             
          echo '&lt;/form&gt;&lt;/center&gt;';
          }
      }
      echo '&lt;center&gt;&lt;table style="margin: 20px; margin-top: 40px;"&gt;';
      $result = mysqli_query($query, "SELECT * FROM duelling WHERE `duel_id` = '$duel_id' ORDER BY `timestamp` DESC") or die(mysqli_error($query));
      //THIS IS THE WHILE LOOP WHICH DISPLAYS ALL LOGS ON REFRESH
      while ($row = mysqli_fetch_array($result)) {
          //$spell, $name, $defence ARE DEFINED HERE, ANOTHER 20 LINES
          echo '&lt;tr&gt;&lt;td style="padding: 5px; color: #a20d0d; font-family: \'Courier New\', Courier, monospace; text-align: right;"&gt;' . date('d.m.y H:i', $row['timestamp']) . '&lt;/td&gt;&lt;td style="padding: 5px;"&gt;' . $name . ' used ' . $spell . '. &lt;span style="font-family: \'Courier New\', Courier, monospace; color: #a20d0d; font-size: 10px;"&gt;' . $defence . '&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;';
      }
      echo '&lt;/table&gt;&lt;/center&gt;';
  }
  </code></pre>