2014-07-15 42 views

回答

0

定時功能最好通過客戶端腳本語言來完成,例如JavaScript(PHP是服務器端)。

但是,客戶端語言不能執行SQL命令,所以我推薦使用AJAX(異步JavaScript和XML),它允許您使用JavaScript函數來觸發PHP函數。

例如,下面將工作:

<script src="wherever you placed your Jquery source file"> 

setTimeout(function(){ 

$.ajax({ 
type: "GET", 
url: "PHP processing gets done on this page", 
data: {query: Search_Data}, //Search_Data is any data you wish to send to the next  page. 
cache: false, 
success: function(html) 
{ 
$("#result").html(html).show(); 
} 
}); 

}, 10000); //This would set make the AJAX function run in 100 seconds. 
</script> 

<div id="result"></div> // results appear here 

你的PHP文件將是以下類型的:我目前使用它在我的服務器端

<?php 

if(isset($_GET['query'])){ 

//PHP code for SQL statement goes here. 

} 

?> 
+0

燁!但我需要類似的東西,假設一個請求在10分鐘內過期,所以在對請求執行插入查詢之後,mysql應該在10分鐘後爲過期標誌自動觸發更新查詢!我不想依賴於服務器端或客戶端超時! – vipulsodha