[英]How do I get data back from database using setInterval function in php
I want to get data back from my database using setInterval() to do it every 60 seconds. 我想使用setInterval()从数据库取回数据,每60秒执行一次。 I want to be able to get back 'message' and 'to' from my database.
我希望能够从数据库中获取“消息”和“至”。
my database table 'message': 我的数据库表“ message”:
id, message, to, from status
1, 'hello', 'Rebecca', 'Erwin' 1
2, 'see you soon', 'Veronica', 'Erwin' 0
3, 'the party was awsome', 'Erwin', 'Rebecca' 1
4, 'can you make it?', 'Veronica', 'UNKNOWN' 1
<?php
$con = mysqli_connect('localhost','user','pass','my_db');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
$sql="SELECT * FROM mesage where status=1";
$result = mysqli_query($con,$sql);
?>
function run_script() { cont_m = 0; cont_s = 0; s = document.getElementById("seconds"); m = document.getElementById("minutes"); window.setInterval( function() { if (cont_s == 60) { cont_s = 0; cont_m++; //get array from database, how do I run the query here get the array and display arrays? m.innerHTML = cont_m; if (cont_m == 60) { cont_m = 0; } } s.innerHTML = cont_s; cont_s++; //}, 1000); every second }, 100);// every 100 miliseconds for example purpose }
<body onload="run_script()"> <p> <span id="minutes">0</span>:<span id="seconds">0</span> </p> </body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.