mysql表示例:
<table>
<tr>
<td>id</td>
<td>value</td>
</tr>
<tr>
<td>aa</td><td>1111</td>
</tr>
<tr>
<td>bb</td><td>1111</td>
</tr>
<tr>
<td>cc</td><td>2222</td>
</tr>
<tr>
<td>dd</td><td>3333</td>
</tr>
<tr>
<td>ee</td><td>1111</td>
</tr>
</table>
<br />
我是新来的,想知道是否有任何可以帮助我用php替换1111s到4444s的值。
我尝试了以下,似乎没有工作:
$ sql =“UPDATE tablename SET id
= REPLACE(id
,'1111','4444')”;
答案 0 :(得分:2)
您应该替换value
,而不是ID
$sql="UPDATE tablename SET `value` = REPLACE(`value`,'1111','4444')";
或只是
$sql="UPDATE tablename SET `value` = '4444' WHERE value = '1111'";
答案 1 :(得分:0)
UPDATE tablename SET value = "4444" WHERE value = "1111"
答案 2 :(得分:0)
UPDATE tablename
SET value='4444'
WHERE value='1111'