T
T
Triborg-3332021-06-10 18:54:24
MySQL
Triborg-333, 2021-06-10 18:54:24

How to make a countdown timer with time from the database + Node JS?

Hello, how to make a node js time countdown from the database?

I need to do this, when you click on the Free Coins button, the time is recorded in the database, and while it is more than 0 , the
player will not be able to take coins until the time is 0
60c2345d811ac423632840.png

, so the question is, how to do this correctly on Node js?
how to select a number from the database?

pool.query(
  "UPDATE `account` SET `freeCoins`= freeCoins -1",
     function(err, rows) {
                      
    }
  );

It takes away even when the value is less than 0... And you need to make it take away when the value is greater than 0.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Neverov, 2021-06-10
@TTATPuOT

When you click on the button, you must put the current timestamp into the base.
Next, check with this timestamp, calculating the timestamp of the new opportunity to click on the button.
UPDATE `account` SET `freeCoins`= NOW()
But it's better to generate a timestamp on the node side and put it in the base already.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question