so i have php code that uses ajax to constantly update/execute the php code into mysql table. along with that is a time_stamp.
what i need is for the php code to be executed every hour.
so once its executed it stores the values into its columns along with a time_stamp.
and then do something like this:
$sDate = date("Y-m-d H:i:s"); // 2015-04-07 07:12:51 $time = mysqli_query($conn, "UPDATE `bullet_store` SET `time_stamp` = '$sDate'"); $result = mysqli_query($conn, 'SELECT SUM(time_stamp) AS value_sum FROM bullet_store WHERE id =1;'); $row = mysqli_fetch_assoc($result); $last_attempt = $row['value_sum']; $nowDate = new DateTime(date('y-m-d h:m:s')); $diff = strtotime($last_attempt) - strtotime($nowDate); if ($diff/5 <= 1) { $stmt = $conn->prepare('UPDATE bullet_store SET LONDON = LONDON + 50 WHERE id=1'); $stmt->execute(); $stmt2 = $conn->prepare('UPDATE bullet_store SET MANCHESTER = MANCHESTER + 50 WHERE id=1'); $stmt2->execute(); $stmt3 = $conn->prepare('UPDATE bullet_store SET BIRMINGHAM = BIRMINGHAM + 50 WHERE id=1'); $stmt3->execute(); $stmt4 = $conn->prepare('UPDATE bullet_store SET LIVERPOOL = LIVERPOOL + 50 WHERE id=1'); $stmt4->execute(); $stmt5 = $conn->prepare('UPDATE bullet_store SET BRISTOL = BRISTOL + 50 WHERE id=1'); $stmt5->execute(); } ``` the above code is a sham i know. so what im trying to do is execute the php code every 5 minutes. im using ajax to keep checking/updating. so i thought the best way would be to store the time along with updating the other columns. and then as ajax is constantly checking the php code. when the time stored is 5 minutes greater than the current_time, then execute the code again. i have no problem executing the php code i am just struggling with setting a 5minute delay.
https://stackoverflow.com/questions/66073212/how-to-compare-time-stored-in-mysql-db-with-nowtime-then-put-it-into-an-if-stat February 06, 2021 at 11:05AM
没有评论:
发表评论