Hello again, i have table in picture below, that table is reading some values of name “var_x” from my microsoft sql database as you can see in table it is happening every second as data is incoming into database. Simply, database is getting variable every one second and sending it to table.
Problem is that i want continuously reading on my .php page, like when new number get into database to show it on page but i get numbers only when i hit refresh page(F5). So lets say if im doing nothing php would be same as it is on this picture and if i hit refresh page i will pick up all new variables until that moment. so… 216, 217, 218…would show up.
Is there a way how to continuously read database on php without hitting refresh?
There is my .php file code:
<!DOCTYPE html>
<html>
<head>
<title> Table with database</title>
<style type="text/css">
table {
border-collapse: collapse;
width: 100%;
color:#d96459;
font-family: monospace;
font-size: 25px;
text-align: left;
}
th{
background-color: #d96459;
color: white;
}
</style>
</head>
<body>
<table>
<tr>
<th>ID</th>
<th>var_x</th>
<th>TIME</th>
</tr>
<?php
try
{
$conn = new PDO("sqlsrv:Server=127.0.0.1,50632;Database=variables_DB","","");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch(Exception $e)
{
die(print_r( $e->getMessage() ) );
}
$tsql = "SELECT * FROM VARIABLESxtable";
$getResults = $conn->prepare ($tsql);
$getResults->execute();
$results = $getResults->fetchAll (PDO::FETCH_BOTH);
foreach($results as $row){
echo '<tr><td>'.' '.$row['var_ID'].' '.'</td><td>'.' '.$row['var_x'].' '.'</td><td>'.' '.$row['TimeStamp'].' '.'</td></tr>';
}
?>
</table>
</body>
</html>
</table>
</body>
</html>