ricmcdonald Posted March 21, 2017 Share Posted March 21, 2017 I have a query that returns a result enclosed in [ ] and I want to remove these brackets I can successfully get rid of the right or left bracket but not both using a trim TRIM(Trailing ']' FROM g.field_value) AS Genre but if i add a TRIM(leading '[' i get an error if the characters were both the same then TRIM(both ']' will work but they are not Do you have a solution Quote Link to comment https://forums.phpfreaks.com/topic/303508-how-to-remove-from-a-query-result/ Share on other sites More sharing options...
NigelRel3 Posted March 21, 2017 Share Posted March 21, 2017 Have you tried... trim(TRAILING ']' from trim(leading '[' from g.field_value)) Quote Link to comment https://forums.phpfreaks.com/topic/303508-how-to-remove-from-a-query-result/#findComment-1544435 Share on other sites More sharing options...
ricmcdonald Posted March 21, 2017 Author Share Posted March 21, 2017 brilliant Nigel works perfictly Quote Link to comment https://forums.phpfreaks.com/topic/303508-how-to-remove-from-a-query-result/#findComment-1544438 Share on other sites More sharing options...
Jacques1 Posted March 21, 2017 Share Posted March 21, 2017 (edited) Where do those brackets even come from? When people need strange string manipulation hacks for their data, there's usually something wrong. Edited March 21, 2017 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/303508-how-to-remove-from-a-query-result/#findComment-1544440 Share on other sites More sharing options...
NigelRel3 Posted March 21, 2017 Share Posted March 21, 2017 I agree - it could be an indication that something is wrong - but data can be sourced from all sorts of places, sometimes it is a case of just having to deal with it. It's especially the case when the data is from a third party and there may be nothing you can do with the source data, you massage it to fit into what you need. Working with data loads can provide a great insight into what people try and do and your left with the impression that relying on people to do anything correctly and consistently is like trying to juggle water. Quote Link to comment https://forums.phpfreaks.com/topic/303508-how-to-remove-from-a-query-result/#findComment-1544441 Share on other sites More sharing options...
Jacques1 Posted March 21, 2017 Share Posted March 21, 2017 If the data comes from a third party (which is pure speculation), then you sanitize it before putting it into the database. Even the weakest programming language is far better at string operations than any MySQL hack. In any case, I'd be careful with literal answers. Users often fail to show their actual problem and only post random ideas they've come up with. Implementing those ideas may not solve the problem at all. Quote Link to comment https://forums.phpfreaks.com/topic/303508-how-to-remove-from-a-query-result/#findComment-1544442 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.