PHP MySQL更新限制 [英] php mysql update limit

查看:83
本文介绍了PHP MySQL更新限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新mysql数据库,其中directory = 0,只需将0值更新为art.

I want to update mysql database, where directory = 0, and just update 5 of records which value 0 to 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

此更新代码正确吗?谢谢.

Is this update code right? thanks.

mysql_query("UPDATE articles SET directory = 'art' WHERE directory ='0' LIMIT 5");

推荐答案

您的语法很好.

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

i will add an order by clause (to be sure)

ORDER BY `Id`

查询

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

这篇关于PHP MySQL更新限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆