Showing Data in MySQL Database In Realtime

▼魔方 西西 提交于 2021-01-28 07:51:03

问题


I am building a weather station that will update the weather in "real-time" to a MySQL Database. To give the feel of "real-time" without taking up a ton of space on my MySQL server, I have my weather station updating a single cell in the MySQL database every few seconds. I would like to set up a way for a website to view this change in realtime without refreshing the page. I have tried researching a lot, but I can't quite find what I am looking for (at least with more of an explanation into the JQuery and how it works). Most answers have partial as people have a lot more experience.

I have a little experience with PHP and MySQL (I have just started learning a couple of months ago). This project is more of a way to learn JQuery and AJAX (along with PHP and MySQL). Frankly, I don't know a ton as I am just starting into programming.

If I could get a bit more of an explanation into how the JQuery works and what files I need to be placing the information in, that would be great (a lot of other similar answers had a separate "server" file and a "client" file in PHP. Do I really need that?).

I just don't know where to begin or what to put in what files. Maybe I need a tutorial? Thanks.


回答1:


I think what you are looking for is "Push Technology". But, as a beginner like me, i would introduce you to try out "long pulling". Although is not the best method, but you can learn how real time update works.

I suggest you to create a normal working ajax, then use the code below to repeatly call for update from the server.

jQuery(document).ready(function () {
    interval =  setInterval("checkNewUpdate()",4000); //Set interval for accident checking ajax
}

This function basically retrieve information from the database every 4seconds. This method is not so efficient, but i hope would help you to kick start in push technology.

Visit How do I implement basic "Long Polling"? for more information.



来源:https://stackoverflow.com/questions/22419992/showing-data-in-mysql-database-in-realtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!