Welcome to WebmasterWorld Guest from 54.144.48.252

Forum Moderators: open

Message Too Old, No Replies

How to trim text in my query ?

     
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
9:04 am on Oct 23, 2012 (gmt 0)

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



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]
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
 

Featured Threads

Hot Threads This Week

Hot Threads This Month