|
 |
|
ช่วยดูโค้ดนับถอยหลังทีครับ มันออกจากฐานข้อมูลแค่ตัวเดียวและไม่ให้มันรีเฟรชแล้วเริ่มใหม่ |
|
 |
|
|
 |
 |
|
เป็นโค้ดทั้งหมดครับ ต้องการให้มันรีเฟรชแล้วไม่เริ่มนับใหม่ และมันนับถอยหลังจากฐานข้อมูลแค่ตัวเดียวไม่ออกทั้งหมด ช่วยทีครับ
Code (PHP)
<?php
include 'connect.php';
error_reporting(E_ALL & ~E_NOTICE);
$time = $db->prepare('SELECT result_time, SUBSTRING(result_time,2,3) AS time FROM tbl_result');
$time->execute();
while ($result_time = $time->fetch(PDO::FETCH_ASSOC)) {
$_SESSION['time'] = $result_time['time'];
//echo $result_time['time'];
$hour = convertFromMinutes($_SESSION['time']);
$tt = $hour['hours']." : ".$hour['minutes']." : ".$hour['seconds'];
echo $_SESSION['tt'] = $tt ;
echo "<br>";
}
// function to convert minutes into hours and minutes for a jobsheet.
function convertFromMinutes($job_duration)
{
$hours = floor($job_duration / 60);
$minutes = floor($job_duration % 60);
$seconds = $job_duration - (int)$job_duration;
$seconds = round($seconds * 60);
return array('hours' => $hours, 'minutes' => $minutes, 'seconds' => $seconds);
}
//$job_duration = 78.6; //minutes
//$job_duration = convertFromMinutes($job_duration);
//echo "Job duration = " . $job_duration['hours'] . " Hours "
// . $job_duration['minutes'] . " Minutes " . $job_duration['seconds'] . " seconds ";
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<body onLoad="begintimer()">
<script language="">
var limit="<?=$_SESSION['tt'];?>";
if (document.images){
var parselimit=limit.split(":")
parselimit=(parselimit[0]*3600)+(parselimit[1]*60)+parselimit[2]*1
//alert(parselimit);
}
function begintimer(){
if (!document.images)
return
if (parselimit==1)
// เหตุการณ์ที่ต้องการให้เกิดขึ้น
// window.location='page.php'; ถ้าต้องการให้กระโดดไปยัง Page อื่น
frmTest.submit();
else{
parselimit-=1
curhr=parseInt((parselimit%86400)/3600);
curmin=parseInt((parselimit%86400)%3600/60);
cursec=parseInt(((parselimit%86400)%3600)%60);
if (curhr!==0 && curmin!=0)
curtime="เวลาที่เหลือ <font color=red> "+curhr+"</font> ชั่วโมง <font color=red>"+curmin+" </font>นาที กับ <font color=red>"+cursec+" </font>วินาที "
else
if(cursec==0 && curmin==0 && curhr==0)
{
alert('หมดเวลาแล้วจ้า');
}
else
{
curtime="เวลาที่เหลือ <font color=red> "+curhr+"</font> ชั่วโมง <font color=red>"+curmin+" </font>นาที กับ <font color=red>"+cursec+" </font>วินาที "
}
document.getElementById('dplay').innerHTML = curtime;
setTimeout("begintimer()",1000)
}
}
//-->
</script>
<div id=dplay ></div>

Tag : PHP, HTML/CSS, JavaScript, Ajax, jQuery

|
|
 |
 |
 |
 |
Date :
2015-06-05 12:51:48 |
By :
littlebeer |
View :
995 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดัน ๆ
|
 |
 |
 |
 |
Date :
2015-06-05 15:24:18 |
By :
littlebeer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใน php ผมก็มี session แล้วนะครับ var limit="<?=$_SESSION['tt'];?>"; แต่เหมือนมันมาแค่ตัวเดียว ทำไงให้มาหมดครับ
|
 |
 |
 |
 |
Date :
2015-06-05 15:53:25 |
By :
littlebeer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดัน ๆ
|
 |
 |
 |
 |
Date :
2015-06-05 18:20:37 |
By :
ก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดัน
|
 |
 |
 |
 |
Date :
2015-06-05 21:03:17 |
By :
e |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|