views:

27

answers:

1

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.

+1  A: 

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.

btrandom
Thank you so much! There were some syntax typos I had to change but it works as: $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); }
Mark