Limit the number of characters displayed from mysql in coldfusion
I have a MySql database which is being displayed via Coldfusion, the code to query th开发者_运维知识库e database is:
<cfquery name="GetWp_posts" datasource="#session.odbcname#">
SELECT post_content
FROM wp_posts
ORDER by ID desc
LIMIT 0, 2 </cfquery>
The code that displays the results is:
<cfoutput query="getWp_posts">
<cfif trim(getWp_posts.post_content) is not ""><div class = "courseShortDesc">#getWp_posts.post_content#</div></cfif>
</cfoutput>
How do I limit the amount of characters displayed in the results?
Many Thanks
You want the Left
function
#Left(getWp_posts.post_content, 20)#
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6e3a.html
There is also a MySQL function called SUBSTRING
that can produce similar results.
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring
精彩评论