Question: I have an employees table here to see whether they are in the office or out. I have a php file to select the status from the database. I tried changing the status from out to in and in to out in the database but I cannot see any changes in my php page until I reload it. How can I get my php page change automatically when there is a change in the database?? I m a newbie so please help out... Thanks in advance. I have the php file here:

```
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'pass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT Name,Status FROM Employees';

mysql_select_db('new');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
    echo "Name :{$row['Name']}  <br> ".
         "Status: {$row['Status']} <br> ".
         "--------------------------------<br>";
} 
echo "Fetched data successfully\n";
mysql_close($conn);
?>

```

Answer: 
HTTP is not a asynchronous protocol. The only way to refresh the data on the webpage is to reload the page eg;re-do the SQL query, parse and display the results. You could possibly do what you want using AJAX methods.. but, I do something like this for an "in-house" page to reload it every 5 minutes...

```
<!DOCTYPE html>
<html>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<script type="text/JavaScript">
<!--
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);",timeoutPeriod);
}
//   -->
</script>
<title>TITLE</title>
</head>
<body onload="JavaScript:timedRefresh(300000);">
<?php //do the query, display results ...
?>
</body>
</html>

```
If you really want this, you can do an ajax request every say 5 seconds, send the old values with the request and compare them to the database, if there is a difference you trigger a refresh, this way you only refresh your page when there is an actual update. (or you just update it using ajax every 5 seconds, looks a lot cleaner than a full page refresh)

Both require polling though, there is no easy way to do it without just checking every so many seconds.