http://www.mysqltutorial.org/mysql-trigger...cheduled-event/Pamiętaj, żeby to włączyć:
SET GLOBAL event_scheduler = ON;
https://developer.mozilla.org/en-US/docs/We...Getting_Startedhttp://phpmajster.blogspot.com/2015/06/aja...x-i-obiekt.htmlhttps://dev.mysql.com/doc/refman/5.7/en/create-event.htmlevent_scheduler_ajax.php:
<body style="background:grey">
<input type="text" id="time_to_starting"/> Format: xxxx-xx-xx xx:xx:xx
<input type="text" id="time_to_stopped"/> <input type="number" id="numb"/>
var sch = 'false';
function delete_scheduler(){
sch = 'true';
}
document.getElementById('delete_sch').addEventListener('click',delete_scheduler,false);
var httpRequest;
var timer = document.getElementById('timer');
function makeRequest() {
httpRequest = new XMLHttpRequest();
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
httpRequest.onreadystatechange = alertContents;
httpRequest.open('POST', 'event_sch.php',true);
httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
httpRequest.send('start='+document.getElementById('time_to_starting').value+'&stop='+document.getElementById('time_to_stopped').value+'&intervalx='+document.getElementById('numb').value+'&sch='+sch);
}
function alertContents() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
var stopped = document.getElementById('timer').innerHTML = (httpRequest.responseText);
if(timer.innerHTML.split(':')[0]==document.getElementById('time_to_stopped').value.split(':')[0]&&timer.innerHTML.split(':')[1]==document.getElementById('time_to_stopped').value.split(':')[1]&&timer.innerHTML.split(':')[2]==document.getElementById('time_to_stopped').value.split(':')[2]){
clearInterval(interv);
//console.log('true');
}
} else {
alert('There was a problem with the request.');
}
}
}
var interv = setInterval(makeRequest,1000);
event_sch.php:
<?php
$conn = new mysqli('localhost','root','','turqus');
$query = 'select * from points;';
$query2= 'create event tictactoe on schedule
every '."'{$_POST['intervalx']}'".' second
starts '."'{$_POST['start']}'".'
ends '."'{$_POST['stop']}'".'
do
update turqus.points set col = now();';
$resultx = $conn->query($query2);
$query3 = 'drop event tictactoe';
if($_POST['sch']=='true'){
$conn->query($query3);
}
// var_dump($resultx);
$result = $conn->query($query);
while($result2 = $result->fetch_assoc()){
}
?>
MariaDB [turqus]> SHOW CREATE TABLE points\G
*************************** 1. row ***************************
TABLE: points
CREATE TABLE: CREATE TABLE `points` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`col` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
Do tabeli wstaw jakieś dane, np. takie:
INSERT INTO points VALUES(NULL,'2018-04-28 06:00:00');
Poprawienie tego kodu zgodnie z Twoimi oczekiwaniami zostawiam Tobie.