codesguy Posted February 3, 2015 Share Posted February 3, 2015 I have a mysql table named songs with 3 columns, id, artist,title.Most of the songs in the artist column are correct, ex:artist------------------John DenverLoretta LynnShania TwainLuke BryanBut some of the songs in the artist column are reveresed with a comma, ex:artist-----------------Dever, JohnLynn. LorettaTwain, ShaniaBryan, LukeIs there an easy php code snippet or mysql statement that i can use to reverse the order of first name and last name and remove the comma in the last example so the artst columd matches the first example?I hope this makes sense, thanks, Dale. Link to comment https://forums.phpfreaks.com/topic/294346-mysql-table-column-help/ Share on other sites More sharing options...
CroNiX Posted February 3, 2015 Share Posted February 3, 2015 It would be a lot better to store the first and last name separately, then format how you want on output. Link to comment https://forums.phpfreaks.com/topic/294346-mysql-table-column-help/#findComment-1504750 Share on other sites More sharing options...
Barand Posted February 4, 2015 Share Posted February 4, 2015 Make a copy of your data (just in case) then try UPDATE artist SET name = CONCAT_WS(' ',TRIM(SUBSTRING_INDEX(name,',',-1)),TRIM(SUBSTRING_INDEX(name,',',1))) WHERE INSTR(name,','); Link to comment https://forums.phpfreaks.com/topic/294346-mysql-table-column-help/#findComment-1504764 Share on other sites More sharing options...
codesguy Posted February 4, 2015 Author Share Posted February 4, 2015 Thank you very much Barand! That worked Awesome! Dale. Link to comment https://forums.phpfreaks.com/topic/294346-mysql-table-column-help/#findComment-1504786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.