I have set up series of pages whose display order depends on a changing variable from a common database. Each page posts a value to the database when loaded (ex: page A posts value 1), then begins to count down.
When a user on a different machine clicks on another page, the value is updated (page B posts value 2).
I would like to make it so that page A could read the change in value while it's still counting down and, without refreshing, could redirect itself to another page, let's say C.
Since I already have a PHP script calling the database to update the value, I can't repeat that call without changing the value from what B posted (2) back to (1).
I know I need use AJAX and setinterval(), and I've looked through many, many examples, but I can't seem to find a way to have page A retrieve the value and activate a redirect that doesn't include printing the value in some way (I'm not actually showing the value on the page) or constructing a div (as in HTML - Change\Update page contents without refreshing\reloading the page).
My thinking is that I need to create an external PHP file to query the database and use AJAX to call it repeatedly and pass the updated value to a refresh function in some way.
I'm fairly new and a little clumsy at this so any advice would be appreciated.
Here is the code I am using to initially call the database (which has only one line) and update the value.
<?php
mysql_connect("xxxx", "xxxx", "xxxx") or die;
mysql_select_db("xxxx");
$result = mysql_query("SELECT * FROM database");
$row = mysql_fetch_assoc($result);
$value = $row ['value'];
if ($value == "0"){
mysql_query("UPDATE gym SET value = '1' WHERE id = '1'");
?>