我希望使用setInterval()从我的数据库中获取数据,每60秒执行一次。我希望能够从我的数据库中找回'message'和'to'。
我的数据库表'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>