mysql - Copy last N characters of SQL column in another column (AKA I messed up!) -


i messed big time: added 2000 images phoca gallery , instead of leaving "title" field empty, use filenames title, wrote name of category... renaming each 1 manually pita, i'm sure can done in sql, except don't know how.

what have is:

(15574, 1379, 0, 'thursday, 25.6.', 'thursday-25-6', 'competitions/hrprvprj/25.6/120/vucemilo_filip/_mg_5545.jpg', 1, null, '2015-07-01 16:55:11', 0, '', '', 0, '', 0, null, 0, 212111, 1, 1, 0, '0000-00-00 00:00:00', 13, null, null, null, null, null, null, '', 0, '', '', '', '', '', '', '*'), 

and i'd need is:

(15574, 1379, 0, '_mg_5545.jpg', '_mg_5545.jpg', 'competitions/hrprvprj/25.6/120/vucemilo_filip/_mg_5545.jpg', 1, null, '2015-07-01 16:55:11', 0, '', '', 0, '', 0, null, 0, 212111, 1, 1, 0, '0000-00-00 00:00:00', 13, null, null, null, null, null, null, '', 0, '', '', '', '', '', '', '*'), 

so i'd replace "thursday, 25.6" , it's alias "thursday-25-6" filename of each image, last 12 digits of column image location.

is there string enter in phpmyadmin trick?

thank much!

if pattern same i.e. competitions/hrprvprj/25.6/120/vucemilo_filip/_mg_5545.jpg' may use substring_index function , using not have rely on 12 characters rather can extract last part of string after last / as

mysql> select substring_index('competitions/hrprvprj/25.6/120/vucemilo_filip/_mg_5545.jpg','/',-1) ; +--------------+ |            | +--------------+ | _mg_5545.jpg | +--------------+ 1 row in set (0.00 sec)  mysql> select lower(substring_index('competitions/hrprvprj/25.6/120/vucemilo_filip/_mg_5545.jpg','/',-1)) ; +--------------+ |            | +--------------+ | _mg_5545.jpg | +--------------+ 1 row in set (0.00 sec) 

so may have update command as

update tablename  set  col1 = substring_index(col_file_path,'/',-1), col2 = lower(substring_index(col_file_path,'/',-1)); 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -