Alex Rivera | Logout

How to remove characters from end of field in MySql database

Asked 2012-04-10T03:11:01.747
17

I am looking for a way to remove some characters from the end of a field in my MySql database.

Say I have a table called 'items' and there is a field called 'descriptions', some of those descriptions have <br>'s at the end. There could be a single case, or there could be 2-3 <br>'s at the end of that field.

I need to find a way through PHP/MySql to trim off these <br>'s. There may be other <br>'s in the description that I want to keep, it is just the ones at the end I need removed.

I know I can loop through every entry, check for that tag at the end, if it exists strip it off, and then update the DB with the new value. But this seems like the long way of doing it, and I'm not sure how to best achieve what I am trying to do.

Edit
Report

1 Answer

31

I don't have a mysql instance to test, but something like this would probably do it:

UPDATE myTable
  SET myCol = TRIM(TRAILING '<br>' FROM myCol);

Take a look at some of the string functions.

answered 2012-04-10T03:22:39.997

Your Answer