Michael Eugene Yuen
Michael Eugene Yuen

Reputation: 2528

How to replace multiple rows

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

Answers (3)

fthiella
fthiella

Reputation: 49049

UPDATE tablename
SET    value='4444'
WHERE  value='1111'

Upvotes: 0

sbeliv01
sbeliv01

Reputation: 11820

UPDATE tablename SET value = "4444" WHERE value = "1111"

Upvotes: 0

John Woo
John Woo

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

Related Questions