homepage Welcome to WebmasterWorld Guest from 54.196.162.238
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
add a prefix to fields, where second character is a number
nigelt74




msg:4149288
 12:54 am on Jun 9, 2010 (gmt 0)

Hi all

Ok the situation is this, i have a number of records stored in a database, like this

1, /123456.jpg
2, /abcdef.jpg
3, /234556.jpg


I need to add a prefix to those images that start with a number, but I can't figure out how to do it,

I wrote the following script

UPDATE `zen_products` SET `products_image` = CONCAT('/numerical', `products_image`)
where `products_image` REGEXP '^[^[:alpha:]]'

But unfortunately I had forgotten about the forward slash that prefixes the fields, and I cannot work out how to add that in to my regex, as I keep breaking it

Any help would be greatly appreciated

 

nigelt74




msg:4150869
 11:59 pm on Jun 10, 2010 (gmt 0)

Ok Problem solved, not elegantly but it worked

I ran a query to remove the first character '/' of all the strings

then ran my query slightly modified

UPDATE `zen_products` SET `products_image` = CONCAT('numerical/', `products_image`)
where `products_image` REGEXP '^[^[:alpha:]]'

The ran a query to add a prefix of '/' to all the fields

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved