Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
mysql: a kind of replace all function?
Old 01-29-2009, 10:30 AM mysql: a kind of replace all function?
Skilled Talker

Posts: 83
Trades: 0
hi,

I would like to know how i can easily replace all (for example) '/kgk/site/uploads' with '/uploads' in all fields named 'text' in the table 'content'. Can this be done?

This is because i am preparing my websites on my own server, where they are located in a subfolder of root, but once i upload them they are in the root.

thanks!

Matt
killerwhale65 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-29-2009, 10:38 AM Re: mysql: a kind of replace all function?
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
UPDATE `content` SET `text`=replace(`text`, '/kgk/site/uploads', '/uploads');
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 01-29-2009, 10:40 AM Re: mysql: a kind of replace all function?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Not tested. I don't know how the backtick is used in the case of a function call, so try it before updateing
Code:
--update myTable
--set `text`=case 
--    when locate('/kgk/site')>0 then replace(`text`,'/kgk/site','')
--    else `text`
--  end;

select `text`,case
    when locate('/kgk/site')>0 then replace(`text`,'/kgk/site','')
    else `text`
  end as cleaned
from myTable;
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-29-2009, 10:57 AM Re: mysql: a kind of replace all function?
Skilled Talker

Posts: 83
Trades: 0
thanks, will try!
killerwhale65 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to mysql: a kind of replace all function?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20337 seconds with 12 queries