Can anyone tell me if it's possible to change one field for all rows with a single query? I bought a new domain and now I need to change: http://themes.rock-kitty.net/demo/index.php?wptheme=whatever Code (markup): to http://newdomain.com/demo/index.php?wptheme=whatever Code (markup): I have 2 problems here. 1. I don't know how to do this. 2. whatever is different word for each field. So, I'm wondering if it's possible to do this with a single query or do I need to edit every field manually? There are almost 700 of them. :\ Thanks!
I don't think it can be done in a single query. At least I don't know of any way to use sql to capture the 'whatever' portion of those fields to pass on to the update query. What a difficult table structure, too, btw. All of those 'whatever' portions should be it's own field and your base url in that table should be in a separate table of settings. In that way, you would just have to edit one field. If you didn't have the 'whatever' portion it would simply be a matter of: update tablename set fieldname = 'http://newdomain.com/demo/index.php?wptheme=' where fieldname like 'http://themes.rock-kitty.net/demo/index.php?wptheme=%' Code (markup): Now, it could be possible to write a script that would parse through the database, pull an array of all of the values for 'whatever' and step through update queries to update each row with the appropriate 'whatever'.
Thanks for the reply! I'm really bad at all this MySQL stuff, so I'm going to ask a stupid question. It's not possible to just change the http://themes.rock-kitty.net/demo/index.php?wptheme= Code (markup): part and leave the theme name (e.g. whatever), right? Also, I doubt I'll be able to create a script like you mentioned since I'm not good at php at all, so I guess I'll just run the query you posted and add the names manually. Thanks for the help!
I got bored so here is essentially what you would need for a script to process this: $query = "select distinct fieldname from tablename"; $result = mysql_query($query) or die("Error"); while($obj = mysql_fetch_object($result)){ $whatever = str_replace("Old Html Address Here up to whatever", "", $obj->fieldname); $updatequery = "update tablename set fieldname = 'new html address here up to whatever".$whatever."' where fieldname = 'old html address here up to whatever".$whatever."'"; mysql_query($updatequery) or die("Error"); } PHP: Obviously, this is without the connection info and you would need to replace the occurrences of fieldname, tablename, and the old and new html strings with the appropriate stuff. This doesn't output anything, though you could easily through an echo in there to see where it was in the loop. Something like: echo $obj->fieldname." <br>"; PHP:
usually domai name / url is stored only in one row on config (file / database). try searching if there's any tables containing configuration first.