#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    15
    Rep Power
    0

    Displaying the query result


    I am stuck up with looping a query within a function. For example, I have a function within which has a query which returns the names which starts with 'a'. But i am able to get only one value (first value) from the database.Actually in the db we have more than 1 values for this query.How should i loop the query within the function? Any help is appreciated...

    <cffunction name="getNames" returntype="any">
    <cfargument name="letter" required="true">
    <cfquery name="getNamesfrmDB" datasource="test">
    select * from employee where firstname like '#arguments.letter#%'
    </cfquery>

    <cfreturn getNamesfrmDB/>
    </cffunction>
    <cfoutput>#getNames('a').firstname#</cfoutput>

    Thanks in advance.....
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    <cfset results = getNames( 'a' ) />
    <cfoutput query="results">#results.firstname#</cfoutput>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    15
    Rep Power
    0
    hey thank you..it worked
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    15
    Rep Power
    0

    cfajaxproxy


    Hi Kiteless,
    I have a question on cfajaxproxy.
    I am using cfajaxproxy to fetch the data from db and display it. For example, I have a dropdown which have the country code. On change of the countrycode, it should display the correct country name from db. but its returning undefined value. Below is the code

    <cfajaxproxy cfc="cfcProxy" >

    <script language="javascript">
    function getCountry(code)
    {
    var code=document.getElementById('code').value;
    var object=new cfcProxy();
    object.setCallbackHandler(getCountryResult);
    object.setErrorHandler(errorhandler);
    object.getCountrylist(code);
    }
    function getCountryResult(result)
    {
    alert(result.value);
    document.getElementById('country').innerHTML=result;
    }
    function errorhandler()
    {
    alert("Problems running proxy");
    }

    Country code: <select name="code" id="code" onchange="getCountry();">
    <cfoutput>
    <cfloop query="getCountrylistfrmDB">
    <option value="#code#">#code#</option>
    </cfloop>
    </option>
    </cfoutput>
    </select><br><br>

    <div id="country"></div>

    cfcProxy.cfc is

    <cffunction name="getCountrylist" access="remote" returntype="query">
    <cfargument name="code" required="yes">
    <cfquery name="getCountrylistfrdisp" datasource="test">
    select country from countrycode where code = "#arguments.code#"->
    </cfquery>
    <cfreturn getCountrylistfrdisp>
    </cffunction>
  8. #5
  9. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    I would use Firebug or set up the CF AJAX debugging (http://help.adobe.com/en_US/ColdFusi...0e40-8000.html ) to make sure you know what's happening with the calls.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    15
    Rep Power
    0
    Yea even i am using the debugger. And from that i could make out that the correct value is generated in the cfc but when the value is fetched by the javascript it is giving as undefined.
    Is there anything that i am missing in my code?

    Thanks in advance...
  12. #7
  13. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    15
    Rep Power
    0
    I just wanted to alert and check whether the result is coming back to the page or not since the page goes blank after selecting the dropdown value. If i am not alerting, then in the page its displaying [object Object]. So to fetch that value i was trying result.value.

    Thank you
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    27
    Rep Power
    0
    There is an attribute for the cfajaxproxy tag called jsclassname that you need. Your tag should look as follows:

    <cfajaxproxy cfc="cfcProxy" jsclassname="myProxy" />

    Then in your JS you refer to the jsclassname rather than the cfc name such as:

    var object = new myProxy();

    Then continue on from there.

    Hope that helps.

IMN logo majestic logo threadwatch logo seochat tools logo