监听 mySQL 数据库中的更改(使用 PHP)

发布于 2024-12-22 20:15:44 字数 364 浏览 4 评论 0原文

假设我有一个系统,操作员在其中打开一个槽(这会在 mySQL 数据库中创建一个新行),然后屏幕上会出现一个二维码。用户用 iPhone 扫描它,然后按“批准”,这会将新行中的一列更改为 true

我怎样才能做到当它确实更改为 true 时,操作员屏幕上会弹出一条消息?

我想到了两种可能实现的方法:

  1. 行中的更改可以触发将消息推送到操作员机器的操作。
  2. 如果操作员可以进入页面,则仅当 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:

  1. a change in the row can trigger something that will push a message to the operator's machine.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

霓裳挽歌倾城醉 2024-12-29 20:15:44

我会使用 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).

老街孤人 2024-12-29 20:15:44

简单的解决方案:
只需在数据库 boolHasBeenShowed 中创建一个标志即可。当有人按下批准按钮时,您将 boolHasBeenShowed 设置为 true。

当操作员打开管理页面时,检查数据库中的所有记录WHERE boolHasBeenShowed = TRUE。显示后,立即更新 boolHasBeenShowed = false。这样您就只能看到新批准的记录。

Easy solution:
Just create a flag in your database boolHasBeenShowed. When someone presses approve you set the boolHasBeenShowed 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 the boolHasBeenShowed = false. That way you will only see the newly approved records.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文