?
Solved

get a Data from CFC

Posted on 2011-09-17
9
Medium Priority
?
231 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
How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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. 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…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

764 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