我有一种情况,我需要计算每6小时的剩余时间,每当我查看时间。如何用php和mysql计算剩余的剩余时间?
我有这样的设置:
<div id="time"><div>
<button>trigger</button>
更精确地说,我有一个触发器,得到一次首发:
$(buttom).on('click', function(){
..... send through ajax the current time to a php file
...if success, get the response and place it in the div
});
在php文件我那个时候存储到数据库
if (isset($_POST['time'])){
$storeTime->timestore($_POST['time']);
}
现在发生的事情是,每当我看到div
我应该看到左tim E:
<div id="time">5h:50min<div>
我在30分钟内再次vizit我看到
<div id="time">5h:20min<div>
等。
问题是没有使用ajax或其他东西来回发送时间,而是发送正确的时间。
我在想什么是每次访问页面时发送的时间。第一次将其存储在表中的字段和其他时间将它们存储在一个单独的表场
id time1 time2
1 123456.. 123124..
的time1
保持未修改的,因为它是原来的时间和每一次我访问该页面时我送新的当前时间并更新time2
这里我有点失落。
这是我如何得到time1
:$getTime = $data->getTime($userId);
而且这件事是在每次时间:$time
我也知道,6H是21600
秒
所以
if ($time >= ($newTime + 21600)){
//if the current time is bigger than the first time + 6h it means that 6h have passed
// store the new time in the database for reference as the new main time
} else {
// 6h have not passed yet and we need to calculate how much time is left
//here i get confuzed
}
我知道这篇文章有点混乱,但我希望它是可以理解的。
有什么想法?
感谢
只是为了澄清,你问如何计算时间的剩余量? – 2012-02-18 05:29:29
是的请,我不知道为什么我使它如此复杂:) – Patrioticcow 2012-02-18 05:34:26
让我知道下面是你想要的... – 2012-02-18 05:37:48