简体   繁体   English

在MySQL数据库中的数据更改后刷新页面

[英]Refresh a page after data in MySQL database changes

Good day all, 美好的一天,

Basically what's I've got is a PHP based site tied to a MySQL database all on a local web server (nothing is being accessed from outside of the company). 基本上我得到的是一个基于PHP的站点,它连接到一个本地Web服务器上的MySQL数据库(没有任何东西从公司外部访问)。 The index page displays an image resembling a bar chart. 索引页面显示类似条形图的图像。 Employees of the company will be entering data periodically which will update the image that appears on the index page. 公司的员工将定期输入数据,这将更新索引页面上显示的图像。 The index page will be displayed on a couple different screens throughout the company and I need that index page to refresh after someone alters the data in the database. 索引页面将显示在整个公司的几个不同的屏幕上,我需要在有人改变数据库中的数据后刷新索引页面。

I've been messing around with various AJAX solutions, but as I don't know much about AJAX I'm having trouble adapting something to work the way I need. 我一直在搞乱各种AJAX解决方案,但由于我对AJAX了解不多,我无法按照我需要的方式调整工作。 Here's the way I've was thinking about: -- on the index.php run a JavaScript function every minute or so that gets a response from dataChanged.php 这是我正在考虑的方式: - 在index.php上运行一个JavaScript函数每分钟左右从dataChanged.php获取响应

-- dataChanged.php will query the database and get a timestamp from one of the tables. - dataChanged.php将查询数据库并从其中一个表中获取时间戳。

-- the script on the index.php will then compare the timestamp to the last time the page was refreshed (or some variable that stores such information) and refresh if the data is new. - index.php上的脚本然后将时间戳与上次刷新页面的时间(或存储此类信息的某个变量)进行比较,并在数据是新的时刷新。

I'm somewhat proficient in PHP, but am very limited with JavaScript (and thus AJAX). 我有点精通PHP,但是我对JavaScript(以及AJAX)非常有限。

Can someone get me pointed in the right direction? 有人能让我指出正确的方向吗?

Thanks! 谢谢!

What you want it the standard javascript function setInterval 你想要它的标准javascript函数setInterval

Have it execute a ajax call every now and then to get new data. 让它不时地执行ajax调用以获取新数据。 Try to get a standars librabry that knows this stuff, probably jQuery 尝试获得知道这些东西的标准库,可能是jQuery

Depending on if the chart generation is time consuming or not I would go with different strategies. 根据图表生成是否耗时,我会采用不同的策略。 The preferred way would be to just generate the graph on each call, but if that is very time consuming I think your two-step solution works great. 首选的方法是在每次调用时生成图形,但如果这非常耗时,我认为您的两步解决方案效果很好。

Check out the link http://blog.codebusters.pl/en/auto-refresh-content-after-changes-in-database-ajax . 查看链接http://blog.codebusters.pl/en/auto-refresh-content-after-changes-in-database-ajax

Here you can see how to refresh your page after change in db. 在这里,您可以看到在db中更改后如何刷新页面。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM