php mysql 更新限制
我想更新 mysql 数据库,其中 directory = 0
,然后将 5 条记录
的值 0
更新为 art
>。
解释一下:
id | directory
1 | fashion
2 | 0 //update here into 'art'
3 | travel
4 | fashion
5 | 0 //update here into 'art'
6 | 0 //update here into 'art'
7 | travel
8 | 0 //update here into 'art'
9 | 0 //update here into 'art'
10 | 0 //this is 6th record, do not update, leave the value as '0'.
11 | fashion
这个更新代码正确吗?谢谢。
mysql_query("UPDATE articles SET directory = 'art' WHERE directory ='0' LIMIT 5");
I want to update mysql database, where directory = 0
, and just update 5 of records
which value 0
to art
.
for explain:
id | directory
1 | fashion
2 | 0 //update here into 'art'
3 | travel
4 | fashion
5 | 0 //update here into 'art'
6 | 0 //update here into 'art'
7 | travel
8 | 0 //update here into 'art'
9 | 0 //update here into 'art'
10 | 0 //this is 6th record, do not update, leave the value as '0'.
11 | fashion
Is this update code right? thanks.
mysql_query("UPDATE articles SET directory = 'art' WHERE directory ='0' LIMIT 5");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的 语法 没问题。
我将添加一个 order by 子句(当然)
来查询
your syntax is fine.
i will add an order by clause (to be sure)
to query
你的询问对我来说似乎没有错。
但请注意,您可能还需要指定
order by
子句,以确定哪五个是“第一个”项目:只是作为参考:更新语法
Your query doesn't seem wrong to me.
But note that you might also want to specify an
order by
clause, to be sure which are the five "first" items :Just as a reference : UPDATE Syntax