Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

get a Data from CFC

Posted on 2011-09-17
9
Medium Priority
?
233 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
[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
9 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 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 16

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 16

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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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
 
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 16

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 16

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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