MYSQL PHP 更新每一行的数据 [英] MYSQL PHP update data of each row
问题描述
我有这个问题,我想了一段时间.
I have this question which I'm thinking for some time.
我有一个这样的表格,在浏览器中使用 php 代码显示
I have a table like this shown using php code in browser
username | price | description |
a | aaa | pending | [yes] [no]
b | bbb | yes | [yes] [no]
a | ccc | no | [yes] [no]
只有用户名、价格和描述来自mysql数据库.
only username, price and description are from mysql database.
对于 [yes] 和 [no] 是查询此的按钮发布.products 是我的表名
for the [yes] and [no] is the button post to the query of this. products is my table name
[yes] = UPDATE products SET description='YES' WHERE description='PENDING'
[no] = UPDATE products SET description='NO' WHERE description='PENDING'
我可以用我的查询做什么?我想要是和否按钮只更新一行,我可以使用 GROUP BY 吗?我使用的查询是完全错误的,因为每当我有多个待处理时,它都会将所有待处理变为是.
What can I do with my query? I want the yes and no button update only a single row, Can I use GROUP BY ? The query I used is totally wrong as it changes all pending into yes whenever I have more than one pending.
推荐答案
获取数据后,将每个对象的 id 保存在id"HTML 属性上.您可以通过将其设置为 id="row-id" 之类的内容来实现.
When you get the data, save the id of each object on the "id" HTML attribute. You can do this by setting it to something like id="row-id".
然后,当您更新时,您只需使用 php 获取 id 即可将其添加到您的查询中.
Then, when you update, you just use php to grab the id and you can add it to your query.
"UPDATE products SET description='YES' WHERE id=:id"
这篇关于MYSQL PHP 更新每一行的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!