数据库
首页 > 数据库> > PHP MySQL更新限制

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

标签:php,insert-update
来源: https://codeday.me/bug/20191013/1907183.html