Reputation: 2528
mysql table example:
<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 />
I am new to here and wondering if any can help me replacing value of 1111s to 4444s with php.
I have tried the follow and didn't seem to work:
$sql="UPDATE tablename SET id
= REPLACE(id
,'1111','4444')";
Upvotes: 1
Views: 120
Reputation: 263723
you should replace the value
,not the ID
$sql="UPDATE tablename SET `value` = REPLACE(`value`,'1111','4444')";
or simply
$sql="UPDATE tablename SET `value` = '4444' WHERE value = '1111'";
Upvotes: 2