How to remove double slashes from column in MySQL? - mysql

I have recently found a bug in my website that has been inserting an extra backslash in the URL. I have fixed the bug, but would like to clean up my historical data.
My table name is visits and column name is url. Some of the example URLs in the field are:
www.mysite.com//
www.mysite.com//restaurant/mcdonalds/
www.example.com//
How can I do a find and replace on // to change it to / in MySQL?
I would greatly appreciate any help. Thanks!

update visits set url=replace(url, '//', '/');

Related

How can i generate url with hyphens from title column in mysql table

I have a mysql table with two columns: Title and url. The url should be from title, and can be created by removing spaces and all characters including spcial characters, then replacing thme with hypens (-)
For example
If the title column is: Tell us more about your #project"
Then Url column becomes: Tell-us-more-about -your-project
Somebody please tell me an sql statement i can use to do that
I just need help for anyone willing to share the knowledge. Please post in ur proposal so i can try
update tb set url=replace( replace(title,' ','-'), '#','-')
in your case will do the job but in general you have to braket
multiple time the internal replace with the new character to be replaced :
replace( (expr) ,'(special char)','-')
You need php str_replace and strtolower or you use Apache Module mod_rewrite

SQL Replace some text of each string of a column

I have a database table that contains a column named: "shortLink".
This column contains a short link of an address of each row in the table.
I use the tinyurl.com services for the short links. The short link looks like this: https://tinyurl .com/randomletters.
Recently I figured out that I need to change the shortlinks to their preview short link version: https://preview.tinyurl .com/randomletters.
The only difference between the two link formats is that there is a prefix preview. between https:// and tinyurl.
Since I have hundreds of rows in the sql table I cannot fix this manually.
Is there any way to convert each shortlink (by adding the prefix preview. in the address) to its preview format with code in sql?
Thanks.
PS - Notice that there is a gap between tinyurl and .com in the link formats above. This gap is added intentionally because the forum would not let me publish the question otherwise.
-- this will update the field for you where it does not already have the preview. in it.
UPDATE YourTable
SET shortlinks= REPLACE( shortlinks, 'https://tinyurl .com', 'https://preview.tinyurl .com')
WHERE shortlinks NOT LIKE 'https://preview.tinyurl%'
You can just use an update:
update t
set shortlink = concat('http://preview.', substring(shortlink, 8))
where shorlink like 'http://tinyurl%';
Bro try this. first, remove all spaces in URL on anywhere then replace 'tinyurl' to
'preview'
UPDATE [Table_Name]
SET shortLink= REPLACE(REPLACE( shortLink, ' ', ''),'tinyurl', 'preview')

Add specific character before / after / certain position of the text string in mysql

I would like to get value like this : 1/2/3/4/5 from this value : 12345 in mysql without using a function.
can somebody help me ?
Thanks for your responses.
I got solution of my problem here
Get image url in prestashop
and here is sql for adding character (here it is a '/') between each character of a string
SELECT if (length(table.field)>1,concat(mid(table.field,2,1),'/'),''),if (length(table.field)>2,concat(mid(table.field,3,1),'/'),''),if (length(table.field)>3,concat(mid(table.field,4,1),'/'),''),if (length(table.field)>4,concat(mid(table.field,5,1) FROM table

MySQL url column contains items with unwanted double forward slash

Table: pages
Field: url
Issue: http://google.com//search?q=something
I have a few thousand rows where this has happened I would like a query that removes the following in bold if that is possible..
http://google.com//<--- remove the extra forward slash
http:// <--- Not to be touched
If anyone knows a MySQL query for this that would be great!
Thanks
You can use the REPLACE function. It requires three parameters
first is the source string,
second is the string to be searched for
and third is the string to replace
UPDATE pages SET url=REPLACE(url, '.com//', '.com/') WHERE url LIKE '%.com//%'

remove thousand dots in a column in a table in a mysql joomla database

Joomla, mysql database. laqdf_base Table qdf_joomleague_person: in knvbnr field you can see numbers in different formats 22.333.333 and 12345678.
What exactly (for a very fresh newbie) do I have to do, within PhpMyAdmin to update the table so all numbers in knvbnr shows numbers in 12345678 format (no "." in them)
I cant post images cause I dont have 10 points yet! Sorry
You can use MySQL's replace() function. Example:
update qdf_joomleague_person set knvbnr = replace(knvbnr, '.', '');