我有一個PHP腳本,它需要一個Instance-ID
(int)的數組,併爲每個數據執行一個SQL查詢,將結果寫入表中。在PHP上繼續執行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);
}
_setInterval_ now google this term。 – itachi 2013-04-27 07:47:49
您必須將'AJAX'與'setInterval()'一起使用,這樣每個時間間隔ajax請求才會獲取新數據。 – 2013-04-27 08:01:44