homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

How to trim text in my query ?

Msg#: 4511170 posted 8:15 am on Oct 23, 2012 (gmt 0)


I need to make a query (mysql database) for get the content of a specific texarea field. For do that I use the follow query:

SELECT `mytextareacolumn` FROM `my_table` WHERE `user_id` = [user_id]

Using this query allow me to get the full content of the texarea for each of my users but my goal was to get only the first 200 character and not the full text. Somebody told me is possible to do something using the SQL functions such as SUBSTR but I don't know how to include this function in my query.

I'm not a coder just a poor newbie.

Anybody can suggest me something please?




WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Msg#: 4511170 posted 9:04 am on Oct 23, 2012 (gmt 0)

(returns) a substring len characters long from string str, starting at position pos

SELECT SUBSTRING(`mytextareacolumn`,0,200) AS `mytextarea200` FROM `my_table` WHERE `user_id` = [user_id]


Msg#: 4511170 posted 3:00 pm on Nov 16, 2012 (gmt 0)

sorry guy I forget to thank you for pointing to me on the right direction :-(

In my case the follow code do the job:

SELECT SUBSTRING(`myfieldname`,1,200) FROM `mytable` WHERE `user_id` = '[user_id]'

all the best


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved