Solved

get a Data from CFC

Posted on 2011-09-17
9
230 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 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 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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