【发布时间】:2019-10-22 06:43:16
【问题描述】:
我知道 AJAX 可以解决我的问题。但是,我需要帮助我如何在我的特定情况下解决它。我在页面上管理一些分类项目,它们通过 PHP 脚本显示(检查数据库,如果项目可用,如果是,则显示)。我现在想要一个管理页面,我可以在其中通过排序表“切换”以显示或不显示项目(将其设置为可用或不可用。
我需要的是:如果单击按钮,我想启动一个 php-skript。应该有一个值传递给该脚本(按钮 id)。脚本本身应该打开一个 SQL 连接,根据传递的按钮 ID 更改数据库值。然后关闭连接。 (可选)还可以刷新单击按钮的表(或一个值)。
有人可以帮助我,至少告诉我我需要做什么吗? (jQuery,Ajax?)。 ID 的传递很重要,否则我需要为每个按钮执行功能。
表格条目如下所示:
<tr>
<td>Himbeerhonig</td>
<td id="himbeerhonig">Ja</td>
<td><button type="button" id="himbeerhonig" onclick="function()">press me to execute function</button></td>
</tr>```
(possible PHP pseudocode)
open SQL connection
look for database entry based on the passed ID
change the value of the found entry (!currentValue)
close SQL connection
*optionally*
refresh the <td id="himbeerhonig"> with the updated value.
非常感谢任何帮助!只需要一些关于如何正确执行的提示。到目前为止,这只是我目前很难掌握的一个概念。
【问题讨论】:
-
你应该在stackoverflow.com/questions/5826784/…这个帖子中找到你的答案
标签: javascript php jquery mysql database