监听 mySQL 数据库中的更改(使用 PHP)
假设我有一个系统,操作员在其中打开一个槽(这会在 mySQL 数据库中创建一个新行),然后屏幕上会出现一个二维码。用户用 iPhone 扫描它,然后按“批准”,这会将新行中的一列更改为 true
。
我怎样才能做到当它确实更改为 true
时,操作员屏幕上会弹出一条消息?
我想到了两种可能实现的方法:
- 行中的更改可以触发将消息推送到操作员机器的操作。
- 如果操作员可以进入页面,则仅当 row =
true
时才会加载,但我不知道如何做到这一点。
如果您知道如何做我上面列出的一些事情,或者有不同的想法,请分享,我们将不胜感激:D
Lets say I have a system, in which the operator opens a slot (which creates a new row in a mySQL DB) and then a QR code appears on screen. The user scans it with his iPhone, then presses 'approve', which changes one of the columns in the new row to true
.
How can I make it so when it does change to true
, a message will pop up on the operator screen?
I thought of two ways that might be possibly done:
- a change in the row can trigger something that will push a message to the operator's machine.
- if the operator can go into a page, that will only load up when the row =
true
, but I can't figure out how to do that.
If you know how to do some of the stuff I listed above, or have a different idea, please share it, it will be highly appreciated :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会使用 AJAX 调用。制作一个 php 页面来检查数据库并返回一个非常简单的是/否响应,可由 javascript 读取。然后,使用ajax每隔一段时间(例如每5秒)查询一次,直到页面返回yes。之后,您可以轻松地提醒用户(javascriptalert() 函数可以工作,或者您可能想要编写一些更奇特的代码)。
I would use an AJAX call. Make a php page that checks the database and returns a very simple yes/no response that can be read by javascript. Then, use ajax to query that on an interval (such as every 5 seconds) until the page returns a yes. After that, you can easily alert the user (the javascript alert() function would work, or you might want to code up something fancier).
简单的解决方案:
只需在数据库
boolHasBeenShowed
中创建一个标志即可。当有人按下批准按钮时,您将boolHasBeenShowed
设置为 true。当操作员打开管理页面时,检查数据库中的所有记录
WHERE boolHasBeenShowed = TRUE
。显示后,立即更新
boolHasBeenShowed = false
。这样您就只能看到新批准的记录。Easy solution:
Just create a flag in your database
boolHasBeenShowed
. When someone presses approve you set theboolHasBeenShowed
to true.When the operator opens the admin page, check the database for all the records
WHERE boolHasBeenShowed = TRUE
. As soon as they have been showed,UPDATE
theboolHasBeenShowed = false
. That way you will only see the newly approved records.