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.
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.
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.
Here is my current (reduced) code of that page:
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 && $row['member_2'] !== $member_id) { echo '<meta http-equiv="refresh" content="0; url=redirect.php" />'; exit; } else { //IRRELEVANT FUNCTIONS if ($my_turn == false && $row['winner'] == 0) { //IRRELEVANT FUNCTIONS } else { echo '<center><form action="spell.php" method="post"><table style="margin: 20px;">'; //300 LINES OF DYNAMIC FORMS AND INPUTS echo '</form></center>'; } } echo '<center><table style="margin: 20px; margin-top: 40px;">'; $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 '<tr><td style="padding: 5px; color: #a20d0d; font-family: \'Courier New\', Courier, monospace; text-align: right;">' . date('d.m.y H:i', $row['timestamp']) . '</td><td style="padding: 5px;">' . $name . ' used ' . $spell . '. <span style="font-family: \'Courier New\', Courier, monospace; color: #a20d0d; font-size: 10px;">' . $defence . '</span></td></tr>'; } echo '</table></center>'; }