仅在剩余 xxx 时间后才使计时器重置为特定数量 (PHP)

发布于 2024-09-10 15:52:01 字数 761 浏览 5 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榕城若虚 2024-09-17 15:52:01

还没有测试过,我也不确定,但这是我首先想到的

$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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文