微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP MySQL更新限制

我想更新mysql数据库,其中目录= 0,并且只更新5条记录,每条记录的值为0.

解释:

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐