gpt4 book ai didi

php mysql更新限制

转载 作者:行者123 更新时间:2023-12-01 22:44:16 27 4
gpt4 key购买 nike

我想更新 mysql 数据库,其中 directory = 0,并且只更新 5 条记录,其中值 0art

解释:

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");

最佳答案

你的syntax很好。

我将添加一个 order by 子句(确定)

ORDER BY `Id`

查询

UPDATE articles SET directory = 'art' WHERE directory ='0' ORDER BY id LIMIT 5

关于php mysql更新限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5528885/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com