homepage Welcome to WebmasterWorld Guest from 54.226.80.55
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
How to trim text in my query ?
matchipette




msg:4511172
 8:15 am on Oct 23, 2012 (gmt 0)

hello

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?

thank

 

phranque




msg:4511192
 9:04 am on Oct 23, 2012 (gmt 0)

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring
SUBSTRING(str,pos,len)
(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]

matchipette




msg:4519724
 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

cheers

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