How to make PHP countdown?

  1. Time to take from the database, let it be $ date_bd
  2. Current time $ date = time ()
  3. Difference: $ date2 = $ date- $ date_bd
  4. Condition: If $ date_2> = 900, Then:

How to make the countdown go, for example: "Wait, 14. minutes left" 13.min, etc.?

    1 answer 1

    This can be done using ajax, by timer, say once a minute, or once a second, send a request to the server and find out how much is left.

    Or, transfer the value of $date and $date2 to js, ​​every second to js reduce $date and, if the condition is met, send a request to the server (if needed) to perform some action.

    The 2nd option is preferable, so as not to pull the database every time, etc.

    • Thanks for the advice, solved the problem differently, just added 900 to angular 777 to $ date2