EnexoOnoma
EnexoOnoma

Reputation: 8836

Find all links in MySQL that contains a specific string and remove it from all

I am trying to remove the "http://www.mydomain.com/?" from my links in my database, where it is found. Is there any easy way to do it automatically ?

My links are on table wp_postmeta. The meta_key is called _tdomf_custom_permalink and the links are in meta_value. As i said, the links have this structure http://www.mydomain.com/?http://www.anotherdomain.com/ and the http://www.mydomain.com/? must be removed.

Thank you!

Upvotes: 1

Views: 873

Answers (2)

Nemoden
Nemoden

Reputation: 9056

UPDATE wp_postmeta set _tdomf_custom_permalink = replace(_tdomf_custom_permalink, 'http://www.mydomain.com/?', '') WHERE _tdomf_custom_permalink like 'http://www.mydomain.com/?%'

Upvotes: 2

pufos
pufos

Reputation: 2930

Hy , that's simple

$query = "SELECT links FROM tabe_name";
$result = msqyl_query($query);
while($row = mysql_fetch_assoc($result)) {
    $id = $row['id'];
    $replace = str_replace("http://www.mydomain.com/?","",$row['links']);
    $query_replace = mysql_query("UPDATE table_name SET link = '$replace' WHERE id = '$id'");
}

This code is understandable to you if you are a begginer, because there are ways to do it in a single sql query.

Upvotes: 0

Related Questions