PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 9, 2022

[FIXED] Replacing SQL field content from pattern till the end of line

 February 09, 2022     mysql, phpmyadmin     No comments   

Issue

I am struggling with a problem in my database. Basically, I have lots of data with various content but luckily I have always added "Kind Regards" keywords in posts and after that I have added various social media links. The links are sometimes the same and sometimes different. But the keyword "Kind Regards" is always there. The structure is like this

Kind Regards 
Linkedin Facebook Google Image link 
Some Random Text 

I want to replace everything after Kind Regards including Kind Regards with just Kind Regards R

i.e. I want to replace "Kind Regards blah_links blah_link blah_links" with just "Kind Regards R"

I tried following query in SQL tab of phpmyadmin but it didin't affect anything

    UPDATE wl_content SET message = REPLACE(message,'Kind Regards%','Kind Regards R') 

I hope anyone can guide me on how to do this replace.


Solution

UPDATE wl_content 
SET message = CONCAT(SUBSTRING_INDEX(message,
                                     'Kind Regards', 
                                     1), 
                     'Kind Regards R')

fiddle



Answered By - Akina
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing