我有一个 PHP 脚本,它接受一个 (int) 数组Instance-ID
并为每个数组执行一个 SQL 查询,将结果写入一个表。
我想每隔 X 秒(或每个新数据)刷新数据库中的数据,但我找不到这样做的方法。
function checkStatus()
{
global $instances_ID;
// Create connection
$con=mysqli_connect("*******","*****","*****","****");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Clear page
echo "<script type='text/javascript'>\n";
echo "document.body.innerHTML = ''";
echo "</script>";
echo "<h3><center>Last Backups:</center></h3><br><br>";
//Build table
echo "<table border='1'align='center'>
<tr>
<th>Instance ID</th>
<th>Backup ID</th>
<th>STATUS</th>
<th>Start Time</th>
<th>End Time</th>
<th>Progress</th>
<th>Servlet</th>
</tr>";
foreach ($instances_ID as $id)
{
$result = mysqli_query($con,"SELECT * FROM `instance_backups` WHERE INSTANCE_ID='".$id."' ORDER BY `instance_backups`.`START_TIMESTAMP` DESC LIMIT 1");
$row = mysqli_fetch_array($result);
echo "<tr>";
echo "<td align='center'>" . $row['INSTANCE_ID'] . "</td>";
echo "<td align='center'>" . $row['INSTANCE_BACKUP_ID'] . "</td>";
echo "<td align='center'>" . $row['STATUS'] . "</td>";
echo "<td align='center'>" . $row['START_TIMESTAMP'] . "</td>";
echo "<td align='center'>" . $row['END_TIMESTAMP'] . "</td>";
echo "<td align='center'>" . $row['PROGRESS_PERCENTAGE'] . "</td>";
echo "<td><input type=button onClick=location.href='******' value='Immidiate Backup'>";
echo "</tr>";
}
echo "</table>";
//Close the connection
mysqli_close($con);
}