0

I want to construct a countdown timer so the customer gets discount on price if he buys the product before countdown ends.

I've search internet and found a lot about countdown timer using Jquery, Javascript...

But how can i say in PHP that if the countdown is running then the product has 50% discount Else if countdown ends(00:00:00) delete discount, return product's price to normal.

The price is stored in the database.

2
  • Your PHP doesn't need a timer. Just check the current time against the time your countdown ends. Commented Jan 3, 2012 at 14:41
  • 2
    You should store in database an end date (datetime actually) and check if the current time is before this `end date. Commented Jan 3, 2012 at 14:42

2 Answers 2

1

No need for timer. Jut store discount date time in database with product.

and if purchase time is within that time apply 50% discount else no discount. You can do this by any means either apply if/ else condition using PHP or handle if/else and datetime comperisions in mysql query.

Sign up to request clarification or add additional context in comments.

Comments

1

You just need to store in database the end time of countdown with something like this

INSERT INTO user_offers SET countdown_end = DATE_ADD(NOW(),INTERVAL 5 MINUTE), user = ...

This will insert row with current time + 5 minutes. Assuming that you have logged in user, you will insert item id and user id, otherwise you need to develop your own way to recognize user (cookie for example), so that refreshing page would not refresh countdown.

Then you will need some jQuery (I like jQuery, but you can use whatever you want) magic for countdown, like this plugin http://keith-wood.name/countdown.html

When user clicks on ORDER NOW button (or smthing like that) you just check user_offers table like this

SELECT countdown_end FROM user_offers WHERE countdown_end > NOW() AND user = ...

If it returns something than you know, that he clicked in limit :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.