Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2011
    Posts
    2

    Unanswered: SQL query to replace part of field in PHPMyAdmin

    Hi,

    I have a table called 'wp_postmeta' (Wordpress) which contains a column called 'meta_value'. A typical field in this column looks like this:

    Code:
    a:22:{s:12:"productimage";s:104:"http://www.disobeyclothing.com/wp-content/themes/eCommerce3/images/tshirts/SurveillanceSociety-Black.png";s:13:"productimage1";s:104:"http://www.disobeyclothing.com/wp-content/themes/eCommerce3/images/tshirts/SurveillanceSociety-White.png";s:13:"productimage2";s:0:"";s:13:"productimage3";s:0:"";s:13:"productimage4";s:0:"";s:13:"productimage5";s:0:"";s:13:"productimage6";s:0:"";s:5:"price";s:5:"10.50";s:12:"spPrdLstDate";s:0:"";s:12:"specialprice";s:4:"0.00";s:6:"weight";s:3:"250";s:9:"istaxable";s:0:"";s:4:"size";s:12:"S,M,L,XL,XXL";s:5:"color";s:11:"Black,White";s:10:"size_stock";s:5:",,,,,";s:11:"color_stock";s:2:",,";s:19:"is_check_outofstock";s:0:"";s:9:"initstock";s:0:"";s:8:"minstock";s:1:"0";s:11:"isshowstock";s:0:"";s:14:"affiliate_link";s:0:"";s:8:"posttype";s:7:"product";}
    I'd like to replace all instances of 'http://www.disobeyclothing.com' with 'http://www.projectdisobey.com/disobeyclothing/uk'.

    I've tried to run the following query but each time I run it, it wipes all data in the field:

    Code:
    UPDATE wp_postmeta set meta_value=replace(meta_value, 'http://www.disobeyclothing.com', 'http://www.projectdisobey.com/disobeyclothing/uk')
    I've also tried this query, but it has the same effect:

    Code:
    UPDATE wp_postmeta 
    SET meta_value = replace(LTRIM(RTRIM(meta_value)), 'http://www.disobeyclothing.com', 'http://www.projectdisobey.com/disobeyclothing/uk');
    Any suggestions as to what I might be doing wrong (and how to do it right)?

    Thanks!

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by harveylester View Post
    I've tried to run the following query but each time I run it, it wipes all data in the field:
    Of course it does, because you do not specify a WHERE clause.

    Btw: this forum is for Microsoft SQL Server. I doubt that you are using that, given that fact that you mention PHPMyAdmin...

  3. #3
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    I have tried your code on SQL Server 2008 and it works perfect, using a varchar(max) as data type.
    Including a WHERE clause or not, should not give any other result.
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  4. #4
    Join Date
    Nov 2011
    Posts
    2
    Yeah, upon further inspectation I can that the query worked just fine, and the field data has been replaced appropriately, but for some reason, after running the query all the product pages on my eCommerce site appear blank, as if the data has been wiped.

    Any idea what this could be? I'm a bit of a Newbie when it comes to SQL...

    Thanks

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by harveylester View Post
    Any idea what this could be?
    could be any number of things (html, php, ajax...)

    but mysql it ain't

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Aug 2012
    Posts
    1
    UPDATE wp_postmeta
    SET meta_value = replace(LTRIM(RTRIM(meta_value)), 'http://www.disobeyclothing.com', 'http://www.projectdisobey.com/disobeyclothing/uk');
    WHERE meta_value like '%http://www.disobeyclothing.com%'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •