I want to transfer data from one table to another table on a specific day (Friday at 20:00) every week. I also want to reset the data from the first table every Sunday.
When I run this line it sends the correct data to the right table (table1).
$sql = "INSERT INTO table1 (Name, Email, Phone, Work, Week)
VALUES ('$name', '$email', '$phone', '$work', '$weekNumber')";
$sql = "INSERT INTO table2 (Name, Email, Work, Week) SELECT Name, Email, Work, Week FROM table1 Where Week = ('$weekNumber') ORDER BY RAND() LIMIT 1";
You can do this easily with event scheduler in MySQL
As as example, you could use the following to do a specific task everyday:
DELIMITER ;; CREATE EVENT UpdateData ON SCHEDULE EVERY DAY STARTS '2016-10-10 00:00:00' -- This is scheduled to start from '2016-10-10' and updates data every day DO BEGIN UPDATE table1 SET Status = 1 WHERE Status = 0; UPDATE table2 SET Status = 1 WHERE Status = 0; END;; DELIMITER ;