The Little Guy Posted February 13, 2009 Share Posted February 13, 2009 I would like to append text to the end of a string in the database. For example: If a cell has this text in it: "I am a string" and I want to add something to the end of it, so the result would look like this: "I am a string and I am the addition". Could I do that using MySQL instead of PHP? It would save me a query. If this does work, I would assume I could do this: $str = 'I am the addition'; mysql_query("UPDATE table SET column = (column + '$str') WHERE id = '1'"); Would I be correct or not? Quote Link to comment https://forums.phpfreaks.com/topic/145042-solved-do-i-have-to-do-php-for-this/ Share on other sites More sharing options...
Prismatic Posted February 13, 2009 Share Posted February 13, 2009 Did you try it? Quote Link to comment https://forums.phpfreaks.com/topic/145042-solved-do-i-have-to-do-php-for-this/#findComment-761112 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2009 Share Posted February 13, 2009 It would be CONCAT() not + http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat Quote Link to comment https://forums.phpfreaks.com/topic/145042-solved-do-i-have-to-do-php-for-this/#findComment-761113 Share on other sites More sharing options...
The Little Guy Posted February 13, 2009 Author Share Posted February 13, 2009 OK cool, Thanks! here was my final result: mysql_query("UPDATE people SET relations = TRIM(LEADING ',' FROM (CONCAT(`relations`, '$str'))) WHERE id = '$link'"); Tell me if it can be improved? Quote Link to comment https://forums.phpfreaks.com/topic/145042-solved-do-i-have-to-do-php-for-this/#findComment-761114 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.