2016-01-12 58 views
0

我寫在與PHP tr和td標籤表計時,下面的代碼顯示它如何刷新一段或一段頁面的php與外部重新編碼?

$time_now=time(); 
$time_check=$fetch_time ['time_vam_give']+($durday1*24*60*60); 
$remaining=$time_check-$time_now; 
$time_remain_day=floor(($remaining)/(24*60*60)); 
$hours_remaining = floor(($remaining % 86400)/3600); 
$minute_remainig=floor((($remaining % 86400) % 3600)/60); 
$second_reminig=((($remaining % 86400) % 3600)%60); 
Echo 「<table><tr class='tr1' style='background-color: #CC8A10' > 
<td class='td1' style='background-color: #CC8A10'>Day</td> 
<td class='td1' style='background-color: #CC8A10'>Hour</td> 
<td class='td1' style='background-color: #CC8A10'>Minute</td> 
<td class='td1' style='background-color: #CC8A10'>Second</td></tr> 
<tr class='tr1'><td class='td1' style='background-color: #FC1359'>$time_remain_day</td> 
<td class='td1' style='background-color: #FC1359'>$hours_remaining</td> 
<td class='td1' style='background-color: #FC1359'>$minute_remainig</td> 
<td class='td1' style='background-color: #FC1359'>$second_reminig</td></tr>」; 

而對於刷新我有一個刷新所有頁面的是這個代碼

$page = $_SERVER['PHP_SELF']; 
$sec = "5"; 
header("Refresh: $sec; url=$page"); 

但刷新代碼,刷新所有頁面和所有對象應該刷新,我只想要包含Time的變量的表中的代碼,我該怎麼做? 此外,我使用Iframe,但使用此標籤,如頁面的屏幕截圖,它不適合和美麗。

echo " <iframe id='dynamic-content' src='../function/Func1.php' ></iframe>"; 

最好的問候。

回答

1

刷新無需重新加載,你應該使用AJAX

你可以使用這樣的事情

使2 PHP文件第一的index.php

<script src="http://code.jquery.com/jquery-latest.js"> 
 

 
</script> 
 
<script> 
 
    $(document).ready(function(){ 
 
    setInterval(ajaxcall, 1000); 
 
}); 
 
function ajaxcall(){ 
 
    $.ajax({ 
 
     url: 'gettime.php', 
 
     success: function(data) { 
 
      data = data.split(':'); 
 
      $('#days').html(data[0]); 
 
      $('#hours').html(data[1]); 
 
      $('#minutes').html(data[2]); 
 
      $('#seconds').html(data[3]); 
 
     } 
 
    }); 
 
} 
 
</script> 
 

 
<table> 
 
    <tr class='tr1' style='background-color: #CC8A10'> 
 
     <td class='td1' style='background-color: #CC8A10'>Day</td> 
 
     <td class='td1' style='background-color: #CC8A10'>Hour</td> 
 
     <td class='td1' style='background-color: #CC8A10'>Minute</td> 
 
     <td class='td1' style='background-color: #CC8A10'>Second</td> 
 
    </tr> 
 
    <tr class='tr1'> 
 
     <td class='td1' style='background-color: #FC1359'><span id="days">0</span></td> 
 
     <td class='td1' style='background-color: #FC1359'><span id="hours">0</span></td> 
 
     <td class='td1' style='background-color: #FC1359'><span id="minutes">0</span></td> 
 
     <td class='td1' style='background-color: #FC1359'><span id="seconds">0</span></td> 
 
    </tr> 
 
</table>

gettime.php

<?php  
 
$time_now=time(); 
 
$time_check=$fetch_time ['time_vam_give']+($durday1*24*60*60); 
 
$remaining=$time_check-$time_now; 
 

 
$time_remain_day=floor(($remaining)/(24*60*60)); 
 
$hours_remaining = floor(($remaining % 86400)/3600); 
 
$minute_remainig=floor((($remaining % 86400) % 3600)/60); 
 
$second_reminig=((($remaining % 86400) % 3600)%60); 
 

 
echo $time_remain_day . ':' . $hours_remaining . ':' . $minute_remainig . ':' . $second_reminig; 
 
?>

我希望幫你

+0

太感謝了,這對我來說非常有用和正常工作,但互聯網上的代碼正常工作。我的網站位於我的國家的私人網絡中,由於它不採取行動,因此無法訪問。前兩行的代碼導致問題,src =「http://code.jquery.com/jquery-latest.js」這我該如何解決這個問題? –

+0

這是因爲在第一2線I中使用的jQuery庫女巫是必要的,從外部鏈路 所以解決方案是從這個鏈路 https://jquery.com/download/ 下載jQuery和修改此行AJAX