简体   繁体   中英

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). 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. 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

-- dataChanged.php will query the database and get a timestamp from one of the tables.

-- 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.

I'm somewhat proficient in PHP, but am very limited with JavaScript (and thus AJAX).

Can someone get me pointed in the right direction?

Thanks!

What you want it the standard javascript function setInterval

Have it execute a ajax call every now and then to get new data. Try to get a standars librabry that knows this stuff, probably 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 .

Here you can see how to refresh your page after change in db.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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