Solved

CREATE COMPONENT-CFFUNCTION

Posted on 2008-10-03
3
264 Views
Last Modified: 2013-12-24
Hello experts.
I have two queries like:
<cfquery name="q_test1" datasource="#dsn#">
SELECT Mobile_ID, User_ID
FROM dbo.artikel
WHERE User_ID = <cfqueryparam value="#SESSION.User_ID#" cfsqltype="cf_sql_numeric">
   AND Mobile_ID = 1
</cfquery>
<cfquery name="q_test2" datasource="#dsn#">
SELECT Mobile_ID, User_ID
FROM dbo.artikel
WHERE User_ID = <cfqueryparam value="#SESSION.User_ID#" cfsqltype="cf_sql_numeric">
 AND Mobile_ID = 2
</cfquery>
And output:
<cfoutput>#q_test1.Recordcount#</cfoutput>
<cfoutput>#q_test2 .Recordcount#</cfoutput>
The question is how to create component and function and use this in my page.
0
Comment
Question by:Panos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 22634473
1) lets say you are housing your cfc's at [webroot]\comm\cfc\
then comPath is comm.cfc

2) To start - the following code would be saved as test.cfc in your #comPath#
<cfcomponent>
      <cffunction name="getStuff" returntype="query">
            Notice that I set the DSN to Application.DSN so the cfc is aware of it
            Otherwise you need to send the DSN in as an argument just like user_id
            <cfquery datasource="#Application.DSN#" name="getQuery">
            SELECT #arguments.Columns#
            FROM dbo.artikel
            WHERE User_ID = <cfqueryparam value="#arguments.User_ID#" cfsqltype="cf_sql_numeric">
            AND Mobile_ID = <cfqueryparam value="#arguments.Mobile_ID#" cfsqltype="cf_sql_numeric">
            </cfquery>
      <cfreturn getQuery>
      </cffunction>
</cfcomponent>
<!--- end test.cfc --->

3) Then on your web page - you invoke your component sending required var values
<cfinvoke component="#comPath#.test" method="getStuff" returnVariable="Testing">
      <cfinvokeargument name="User_ID" value="#session.User_ID#"/>
      <cfinvokeargument name="Mobile_ID" value="1"/>      
      <cfinvokeargument name="Columns" value="Mobile_ID,User_ID"/>
</cfinvoke>
<cfdump var="#Testing#">
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 31502677
Thank you for your help.
regards
panos
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 22635034
keep in mind that this was a simple example
you can add to it or take away
for ex I added the Columns argument to show you that you can do stuff like that
and if using sql server you can use stored procedures instead of cfqueries in your functions which will run much faster for longer running queries

good luck
0

Featured Post

Don't miss ATEN at NAB Show April 24-27!

Visit ATEN at NAB Show to learn how our "Seamlessly Entertaining" solutions deliver fast, precise video streaming without delays for the broadcasting and media environment. ATEN will showcase its 16x16 Modular Matrix Switch (VM1600) and KVM Over IP Solution (KE6900 series).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question