2011-04-04 18 views
2

從MySQL顯示的字符的數量,查詢數據庫的代碼是:限制我有正在通過的Coldfusion顯示MySQL數據庫中的ColdFusion

<cfquery name="GetWp_posts" datasource="#session.odbcname#"> 
SELECT post_content 
FROM wp_posts 
ORDER by ID desc 
LIMIT 0, 2 </cfquery> 

顯示的結果的代碼是:

<cfoutput query="getWp_posts"> 
      <cfif trim(getWp_posts.post_content) is not ""><div class = "courseShortDesc">#getWp_posts.post_content#</div></cfif> 
     </cfoutput> 

如何限制顯示在結果中的字符數量?

非常感謝

回答

5

你想要Left功能

#Left(getWp_posts.post_content, 20)# 

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6e3a.html

還有一個MySQL的函數調用SUBSTRING,可以產生類似的結果。

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring

+0

這是偉大的 - 即做的工作。非常感謝 – elixireu 2011-04-04 16:51:47

+0

如果可以,請檢查回答的問題。 – 2011-04-04 18:32:13

+1

您可能還想看看CFLib上的http://cflib.org/udf/FullLeft。這是一個增強的left(),它不會切斷單詞,如果這是您需要的。 – 2011-04-04 18:54:58