仅在剩余 xxx 时间后才使计时器重置为特定数量 (PHP)
我有一个 php 脚本,我正在尝试更改。编写原始代码是为了在按下按钮时将倒计时器增加一个从 SQL 中提取的值。
我一直在尝试做的是更改代码,以便时间不会增加,但实际上只有当计时器低于一定量(例如 60 秒)时才重置为特定的剩余时间。例如:在剩余 45 秒时按下按钮;计时器重置为剩余 60 秒。按下按钮 2 分钟不会影响计时器。
原始代码如下所示:
// Price increment
$auction['Auction']['start_price'] += $data['auction_price_increment'];
if(strtotime($auction['Auction']['end_time']) < time()) {
$auction['Auction']['end_time'] = date('Y-m-d H:i:s');
}
// Time increment
$auction['Auction']['end_time'] = date('Y-m-d H:i:s', strtotime($auction['Auction']['end_time']) + $data['auction_time_increment']);
if(strtotime($auction['Auction']['end_time']) < time()) {
$auction['Auction']['end_time'] = date('Y-m-d H:i:s');
}
我很感激有关如何执行此操作的任何和所有想法。
I have a php script I'm trying to alter. The original code is written to increase the countdown timer by a value pulled from SQL anytime a button is pressed.
What I've been trying to do is change the code so that the time doesn't increase but actually resets to a specific remaining time ONLY WHEN the timer is under a certain amount (say 60 seconds). For example: Button is pressed at 45 seconds remaining; Timer resets to 60 seconds remaining. Button pressed at 2 minutes does not affect the timer.
The original code looks like:
// Price increment
$auction['Auction']['start_price'] += $data['auction_price_increment'];
if(strtotime($auction['Auction']['end_time']) < time()) {
$auction['Auction']['end_time'] = date('Y-m-d H:i:s');
}
// Time increment
$auction['Auction']['end_time'] = date('Y-m-d H:i:s', strtotime($auction['Auction']['end_time']) + $data['auction_time_increment']);
if(strtotime($auction['Auction']['end_time']) < time()) {
$auction['Auction']['end_time'] = date('Y-m-d H:i:s');
}
I'd appreciate any and all ideas on how to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
还没有测试过,我也不确定,但这是我首先想到的
$time_to_reset = time() + (60);
if(strtotime($auction['Auction']['end_time']) >= ( $time_to_reset ) {
$auction['Auction']['end_time'] = date('Ymd H:i:s', $time_to_reset)
希望
有帮助。
Haven't tested it and i am not sure but it's the first thing that popped into my mind
$time_to_reset = time() + (60);
if(strtotime($auction['Auction']['end_time']) >= ( $time_to_reset ) {
$auction['Auction']['end_time'] = date('Y-m-d H:i:s', $time_to_reset)
}
Hope it helps.