How to implement dynamic listening database changes?
Want to make a shopping site, want to be when someone buys a product to prompt "Someone buys your goods" such message, but how to listen to the changes in the database? If the database should be a regular query of resources it? (1 times/1s). Thank you, everyone.
------Solution--------------------
I understand the landlord meaning, he means that the current station when someone orders the background staff can immediately get to the next order information, rather than refresh to see.
I currently have the following options,
1, write a mail to send, when there are customers to place a single time when inserting data in the mail sent to the Administrator mail, preferably QQ mail, because QQ can remind, hehe. This way, when someone orders, they immediately know, of course, you can also use text messages (but money, but also delay).
2, the use of JS setinterval every 3 seconds to see if the database has changed, if any, you can do a QQ or Wang Wang's cue tone to prompt the backstage staff have new orders, I do so.
Put down My Code:
var int=setinterval ("Clock ()", 20000);
function Clock () {
$ ("#call_div"). HTML ('
Refreshing screen ...');
var url = "extend/new_dd.php?cache=" +math.random ();
$.get (url,function (Result) {
$ ("#call_div"). HTML (result);
});
}
3, also use JS setinterval but not query database, and when there are customers to order, when inserting data change $_session[odrer_state] inside content is 1, then is the use of JS setinterval every 3 seconds to get content, If it is 1, we do not have the backstage staff have orders, if the backstage has seen the main point of processing and then the $_session[odrer_state] content into 0. The benefit is that database resources are not consumed by too many queries.
In fact, a lot of methods to see how you use the most suitable. Attach the image of the function of my website