PHP/Ajax Countdown Timer

Discussion in 'PHP' started by lukefowell89, Dec 21, 2010.

  1. #1
    Hi Everyone,

    I was wondering if some people could give some suggestions on to an approriate solution to a problem I am having.

    I need to be able to modify an eCommerce platform to be able to have the prices counting down over 24 hours. To do this, we would have special offers where the price is going down and down every couple of seconds. Abit like the bidding TV Channels where you buy at the price it is when you phone in, but the gamble is that you don't know when its going to run out of stock so you have to pitch your bid in when you feel its right.

    I will be able to make all the modifications to do this, I just need to have a think about the theory of the solution I will undertake.

    I want to be able to set in the backend, a product then select its finishing price and starting price, then the period of the timer.(Generally 24 hours). From this can figure out how much the price is to be lowered per minute/second etc.

    When the timer has expired, the price will go back to the normal price again.

    The only feature I am hoping to put on here, is that when someone goes to buy, it freezes the countdown for everyone, until that person has completed the checkout or after a given time period.

    What I really need is the structure of how it will work, the database tables needed, and general theory behind a solution!

    Thanks
     
    lukefowell89, Dec 21, 2010 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    hmm... i think you dont really need a countdown timer here, use the item date and time of selling.

    - when a user visits an item, get the item's date and time

    - check whether the item will still decrease its price
    -- if yes, compare it to the current date and time then just do a mathematical equation here to get the current price(based on time)

    dont do queries everytime the timer starts, just create a class / method that will compare the (items time vs. the current time) vs items price, etc... math will do the trick here, not the timer.
     
    bartolay13, Dec 21, 2010 IP
  3. lukefowell89

    lukefowell89 Peon

    Messages:
    182
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ahh that makes sense, so the timer is purely visual, but when they go to click buy I can then calculate the value seperately, which should match the displayed price.

    The only issue then would be how do I pause the countdown when someone enters the buying process? I am guessing that the countdown (decreasing Price) would have to be a AJAX timer so that I can set a database value to true or false depending on if someone is buying something or not.

    Any other ways around this?
     
    lukefowell89, Dec 22, 2010 IP