Solved

get a Data from CFC

Posted on 2011-09-17
9
227 Views
Last Modified: 2012-05-12
Hi, i have the following CFC

<cffunction access="public" name="myrecords" returntype="any">
      <cfquery datasource="#dsn#" name="abc">
      SELECT * from mytable
      </cfquery>
    <cfif abc.recordcount>
          <cfsavecontent variable="mySelect">
              <cfset str = '<select name="valSelect" id="valSelect">
                        <cfoutput query="abc">
                            <option value="#abc#">#abc#</option>
                      </cfoutput>
                  </select>'>
        </cfsavecontent>
    <cfelse>
          <cfsavecontent variable="xyz">
              <cfset str = "No data returned">
        </cfsavecontent>    
    </cfif>
    <cfreturn str>
</cffunction>

I know this is wrong but how can i do it, leave the else clause!

So pleasew guide if i render the html on cfc and send back to the CFM
0
Comment
9 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 36554060
Here my version:
<cffunction access="public" name="myrecords" returntype="any">
      <cfquery datasource="#dsn#" name="yourQueryName">
      SELECT * from mytable
      </cfquery>
    <cfif yourQueryName.recordcount>
          <cfsavecontent variable="myReturnStr">
              <select name="valSelect" id="valSelect">
                      <cfoutput query="yourQueryName">
                            <option value="#mycolum1#">#mycolum2#</option>
                      </cfoutput>
              </select>'>
        </cfsavecontent>
    <cfelse>
              <cfset myReturnStr = "No data returned">
    </cfif>
    <cfreturn myReturnStr>
</cffunction>

<cfset myStr=myrecords() >

<cfdump var="#myStr#" >

Open in new window

0
 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 36554710
it is retuning me as TEXT rather than the Actual Select, i want th actual Select menu not just text
0
 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 36554721
Ok! i made it working, NO Problem! Thanks

Another Query should i Continue is:

I am getting data as:
 
1            Active
2            Inactive
3            Progress
4            Complete
5            Active + Complete

Now the above 4 i get from my query,
Regarding the 5th how can i Combine the 4th and 1st. I though of using Lists but how i will find the matching record of 1 isActive and 4 is Complete with a list, becoz i do not want to hard Code it!
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 36555015
It is a problem when you do not finish one Question and combine it with your next ideas.

Post here the solution for your original Question and open a new Question for your next requests.

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 52

Expert Comment

by:_agx_
ID: 36555118
>> Ok! i made it working, NO Problem! Thanks

Good.  

But don't forget to VAR scope all of your function variables
0
 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 36555585
Thanks Agx, I will do that!

Have you read my next line of Comment from where i have to get the combined data of the ! and 4 and show on front end but does not want to hard code it
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 36559998
> I though of using Lists but how i will find the matching record of 1 isActive and 4 is Complete with a list, becoz i do not want to hard Code it!

what do you want to put into the value="" parameter when you combine Active and Complete ?

Also, how do you identify active and complete options?   Since you do not have an Order By clause on your select statement, the order could change at any time... then you cannot be guaranteed of having the 1st and 4th be the two values you want.   You need to add an order by or hard code the IDs, or add a flag to the table to identify which two you want to combine
0
 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 36562680
well order by clause will not change, so that issue is resolved!

Just left with Matching stuf i i get the 1,4 how do i display the corrosponding values against it
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 36576661
<|:-)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now