Hi. I know mysql but I don't know how to delete every occurence of a particular phrase. For example if the phrase "I love you" occurs somewhere is the description of a project how do I delete that phrase without deleting the actual record?
If I type in delte from projects where description like = 'I love you';
then the actual records will be deleted, but I want only the phrase itself, not the record to be deleted. Does anyone know how to do that? Do I have to do it in PHP or it possible to do it in MySQL?
Thanks for your help.
delete every occurence of a phrase
Moderator: General Moderators
how about:
Code: Select all
UPDATE projects SET description='' WHERE description like='I love you';delete every occurence of I loveyou
Hi. Thank you for your quick reply. You said the answer was this:
UPDATE projects SET description='' WHERE description like='I love you';
Wouldn't this delete the rest of the description? For example the description might be "Blah blah blah, I love you, blah blah' and then we would lose the blah blahs, wouldn't we?
Thanks again.
Rachel
UPDATE projects SET description='' WHERE description like='I love you';
Wouldn't this delete the rest of the description? For example the description might be "Blah blah blah, I love you, blah blah' and then we would lose the blah blahs, wouldn't we?
Thanks again.
Rachel
uhm, just do:
you could do something like that 
Code: Select all
$query = "SELECT id, description FROM table";
$result = query_db($query);
while ($row = mysql_fetch_array($result)) {
$id = $rowї"id"];
$description = str_replace("I love you", "", $rowї"description"]);
$updatequery = "UPDATE table SET description = '$description' WHERE id = $id";
query_db($updatequery);
}