实时显示 MySQL 数据库中的数据 [英] Showing Data in MySQL Database In Realtime

查看:93
本文介绍了实时显示 MySQL 数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个气象站,它将实时"更新天气到 MySQL 数据库.为了在不占用 MySQL 服务器大量空间的情况下给人一种实时"的感觉,我让我的气象站每隔几秒钟更新一次 MySQL 数据库中的一个单元.我想为网站设置一种无需刷新页面即可实时查看此更改的方法.我已经尝试了很多研究,但我无法完全找到我正在寻找的东西(至少对 JQuery 及其工作原理有更多的解释).大多数答案都是片面的,因为人们有更多的经验.

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.

我对 PHP 和 MySQL 有一点经验(我几个月前才开始学习).这个项目更多的是一种学习 JQuery 和 AJAX(以及 PHP 和 MySQL)的方式.坦率地说,我一无所知,因为我刚刚开始编程.

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.

如果我能对 JQuery 的工作原理以及我需要将信息放置在哪些文件中得到更多的解释,那就太好了(许多其他类似的答案有一个单独的服务器"文件和一个PHP 中的客户端"文件.我真的需要那个吗?).

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.

推荐答案

我认为您正在寻找的是推动技术".但是,作为像我这样的初学者,我会向您介绍尝试长拉".虽然不是最好的方法,但您可以了解实时更新的工作原理.

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.

我建议你创建一个正常工作的ajax,然后使用下面的代码从服务器重复调用更新.

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
}

这个函数基本上每4秒从数据库中检索一次信息.这种方法效率不高,但希望能帮助你开始使用推送技术.

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.

访问如何实现基本的长轮询"?了解更多信息.

这篇关于实时显示 MySQL 数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆