Jump to content

UPDATE SQL Needed


mcmuney

Recommended Posts

For example:

$result = mysql_query("SELECT * FROM Persons WHERE FirstName='Peter is my name' ");
$row = mysql_fetch_array($result);

$replace = str_replace('Peter', 'Jammy', $row['FirstName']);

mysql_query("UPDATE Persons SET FirstName = '$replace'
WHERE FirstName = 'Peter' ");

 

Something like that should set first name to 'Jammy is my name' where 'Peter is my name' was.

 

Link to comment
https://forums.phpfreaks.com/topic/198438-update-sql-needed/#findComment-1041293
Share on other sites

For example:

$result = mysql_query("SELECT * FROM Persons WHERE FirstName='Peter is my name' ");
$row = mysql_fetch_array($result);

$replace = str_replace('Peter', 'Jammy', $row['FirstName']);

mysql_query("UPDATE Persons SET FirstName = '$replace'
WHERE FirstName = 'Peter' ");

 

Something like that should set first name to 'Jammy is my name' where 'Peter is my name' was.

 

 

This SINGLE query would accomplish the same thing as that code above!

UPDATE Persons
SET FirstName = REPLACE(FirstName, 'Peter', 'Jammy')
WHERE FirstName='Peter is my name'

 

No need to query the database for the records, process the records, and then do an update.

Link to comment
https://forums.phpfreaks.com/topic/198438-update-sql-needed/#findComment-1041296
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.