0

I need to create a website counter that decrements value in real time (reduces number by 1 every 10 minutes). This can be done easily in JavaScript i think. However, I need to store the current number (not client side), so that visitors can see the new version of the number every time they visit the website.

The counter is about population of the country.

I am thinking of using data base and PHP for storing information about the current number, but I am wondering if there is a better solution.

Anyone got any ideas? Thanks

  • have you tried any code? – Prashanth Benny Feb 07 '17 at 18:47
  • [This answer](http://stackoverflow.com/a/31322272/1986221) combined with creating a text file that saves an "initial date" (or a database, your choice) and the modulus operator of the division of 10 (`% 10`), which will calculate how many times 10 minutes have passed since the initial date, should be sufficient to calculate what you want. `initial big number - calculated number = remaining count`. I believe you only require to transform a DateTime object to a timestamp, which you'll easily find on Google. – Alejandro Iván Feb 07 '17 at 18:51

1 Answers1

0

You can actually do it in database alone. And PHP just do display it. From what I remember, I used an extra column for counter and used a stored proc to decrement the counter. Then trigger to activate the stored proc every now and then. I think my question before has it. MySQL - How to decrement int value every 24 hours?

Community
  • 1
  • 1
WTFZane
  • 592
  • 1
  • 4
  • 25
  • This is a great advice, thanks. I have tried it, unfortunately server host has turned off Events in phpmyadmin, so I can't use the procedure on schedule. I have tried to do it via Cron job, as some people have suggested in posts, however host has not enabled them in cPanel either (some host...). I will try to contact them to see if they can enable those options tomorrow. If you can think of any other way to do it (in case they won't help me), I would appreciate it. Thanks again. – lupu51nfactum N778 Feb 08 '17 at 17:41
  • Oh, is that so. Because I did that project via `localhost` then when I did another project with a hosting site (hostgator). I think hostgator aren't allowing this kind of job. I just don't know yet if the server in my office will allow. Will keep you updated – WTFZane Feb 09 '17 at 00:09