If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How do i replace string in this scenario ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-27-08, 11:53
alvincks alvincks is offline
Registered User
 
Join Date: Mar 2004
Posts: 74
How do i replace string in this scenario ?

Good day,

When i using following query to pull out the data as following :-

Code:
SELECT url FROM mytable
the url data will show following :-
Code:
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/RXbnq5eW0vo&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RXbnq5eW0vo&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>
but i would like to replace the width and height in specific value say width=200 , height=300 for both occurance, how can i do that ?

meaning i would like to get the data after specific value replaced as show in following :-

Code:
<object width="200" height="300"><param name="movie" value="http://www.youtube.com/v/RXbnq5eW0vo&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RXbnq5eW0vo&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="200" height="300"></embed></object>
many thanks for guidance !
Reply With Quote
  #2 (permalink)  
Old 12-29-08, 08:40
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
width and height appear twice, and you're wanting to change both...

If you're going to be doing this often it may be advised to store it in the db with the format
Code:
<object width="[width]" height="[height]" ...
Because this would make the replacements super easy
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 12-29-08, 09:43
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
better yet, store the url along with its attributes and construct the html from those values -- don't store the actual html itself
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 12-29-08, 09:43
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Even better suggestion! ++1
__________________
George
Twitter | Blog
Reply With Quote
  #5 (permalink)  
Old 01-01-09, 07:26
alvincks alvincks is offline
Registered User
 
Join Date: Mar 2004
Posts: 74
Thanks all for reply,

but the case here is the URL is user enter, in most case, the URL should take the width and height value from user , only in certain page, the movie need to display in specific size , any chance i can get it replace ?
Reply With Quote
  #6 (permalink)  
Old 01-01-09, 22:54
alvincks alvincks is offline
Registered User
 
Join Date: Mar 2004
Posts: 74
Hi George, i might be little dumb here, do you mind to explain further how your sample can be replace easily ?
Reply With Quote
  #7 (permalink)  
Old 01-01-09, 22:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
yeah, george, go for it!

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 01-02-09, 04:01
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
It's called Replace()
Code:
SELECT Replace([field_name], '[string_to_find]', '[string_to_replace]');
__________________
George
Twitter | Blog
Reply With Quote
  #9 (permalink)  
Old 01-04-09, 08:41
alvincks alvincks is offline
Registered User
 
Join Date: Mar 2004
Posts: 74
Thanks George !

what if the situation here insist me on just change the width and height ?

what can i do for it ?

Code:
<object width="200" height="300"><param name="movie" value="http://www.youtube.com/v/RXbnq5eW0vo&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RXbnq5eW0vo&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="200" height="300"></embed></object>
Reply With Quote
  #10 (permalink)  
Old 01-05-09, 04:03
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
There's obviously a flaw, but here you go!
Code:
Replace(Replace(your_field_containing_the_url, '200', new_width_value), '300', new_height_value)
__________________
George
Twitter | Blog
Reply With Quote
  #11 (permalink)  
Old 01-05-09, 05:26
alvincks alvincks is offline
Registered User
 
Join Date: Mar 2004
Posts: 74
Thanks George !!!
i forgot to mentioned the value of width and length is variable which depend on user define value actually
Reply With Quote
  #12 (permalink)  
Old 01-05-09, 06:17
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Exactly! Which is why you need to reconsider the way in which you store the data.
__________________
George
Twitter | Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On