Solved

get a Data from CFC

Posted on 2011-09-17
9
226 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
Question by:myselfrandhawa
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:myselfrandhawa
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:myselfrandhawa
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

22 Experts available now in Live!

Get 1:1 Help Now