简体   繁体   English

如何使用PHP中的setInterval函数从数据库获取数据

[英]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> 

You are trying to run a timing event on server-side using a client-side js function? 您是否正在尝试使用客户端js函数在服务器端运行计时事件? I don't think that's a very good idea. 我认为这不是一个好主意。 You should check other ways to do this.What you need is a cron , or something similar. 您应该检查其他方法来执行此操作。您需要的是cron或类似的东西。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript-如何从setInterval()函数获取变量? - Javascript - How do I get a variable from a setInterval() function? 如何从Paypal取回数据,以便可以相应地更改MySQL数据库? - How do I get data back from Paypal so I can alter my MySQL database accordingly? 如何显示从javascript调用php函数返回的数据? - How do I display data back from a javascript calling a php function? 传递参数时,如何让setInterval()从函数内部执行单击? - How do I get setInterval() to execute a click from inside a function when passing a parameter? 如何清除函数内的setInterval? - How do I clear this setInterval inside a function? 我如何将数据从 javascript 插入到 php 表中,或者如何使用数据库而不是使用 localStorage 执行以下任务? - how do i insert data into a php table from javascript or How can i do the following task using database instead of using localStorage? 这个javascript函数到底能做什么? 以及如何捕获select中的值以将其重新插入数据库? - what does this javascript function exactly do? and how do i catch the values from select to insert it back into the database? 在另一个函数完成读取输入的每个字母后,如何让 setInterval 函数终止? - How do I get a setInterval function to terminate after another function finishes off reading every letter of the input? 如何从 Javascript 函数获取数据并将其保存到 php 中用户的自定义元字段? - How do I get data from Javascript function and save it to a user's custom meta field in php? 如何在php codeigniter中使用ajax从数据库中获取数据并以模式显示? - How can I get data from database using ajax in php codeigniter and display it in modal?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM