CFfunction - How to create a function in ColdFusion

cffunction - create a function

cffunction.cfm


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cffunction tag example: how to create a function in coldfusion</title>
</head>

<body>
<h2 style="color:Crimson">cffunction Tag Example</h2>

<cfset TotalRecord=GetTotalRecord("cfbookclub", "Books", "BookID")>
<cfoutput>
 <b>Total Record [DataSource cfbookclub; Table BOOKS]: </b> #TotalRecord#
</cfoutput>
<cffunction name="GetTotalRecord" access="remote" returntype="numeric" description="Return table number of records">
 <cfargument name="DataSource" type="string" required="yes">
 <cfargument name="TableName" type="string" required="yes">
    <cfargument name="FieldName" type="string" required="yes">
 <cfquery name="qTableData" datasource="#arguments.DataSource#">
     SELECT COUNT(#arguments.FieldName#) AS TotalRecord FROM #arguments.TableName#
    </cfquery>
    <cfreturn qTableData.TotalRecord>
</cffunction>
</body>
</html>





More ColdFusion examples