限制coldfusion中mysql显示的字符数

时间:2011-04-04 16:12:48

标签: mysql coldfusion

我有一个通过Coldfusion显示的MySql数据库,查询数据库的代码是:

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

如何限制结果中显示的字符数?

非常感谢

1 个答案:

答案 0 :(得分:5)

您需要Left功能

#Left(getWp_posts.post_content, 20)#

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

还有一个名为SUBSTRING的MySQL函数可以产生类似的结果。

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