Skip to main content
May 2, 2007
Answered

isdefined("query.recordcount")

  • May 2, 2007
  • 5 replies
  • 1851 views
I am getting incorrect data when checking the isdefined("query.recordcount") inside of an <cfoutput query="temp"> tag. If the query portion of the query.recordcount in the isdefined funciton is different then the query attribute of the cfoutput tag, the isdefined function returns NO, even if there are records in the query.


    This topic has been closed for replies.
    Correct answer
    I figured the problem out. I had a column called "Replys" from the "Emails" query that had the same name of the second query "Replys". Under CF 5 there was no problem and worked correctly, but under MX 7, the replys.recordcount variable was not found within the cfoutput query="emials" tag.

    The reason I use isdefined is... Depending on conditions, the query "Replys" may or maynot be found on the page. The Replys query only gets created if certain conditions are met.

    The simple fix was to just rename the query.

    5 replies

    Inspiring
    May 4, 2007
    > The reason I use isdefined is... Depending on conditions, the query "Replys"
    > may or maynot be found on the page. The Replys query only gets created if
    > certain conditions are met.

    Right, so that would be:

    structkeyExists(variables, "queryName")

    not:

    isDefined("queryName.recordCount")

    You shouldn't be testing if the recordCount exists, you should simply be
    testing the query exists.

    --
    Adam
    Correct answer
    May 3, 2007
    I figured the problem out. I had a column called "Replys" from the "Emails" query that had the same name of the second query "Replys". Under CF 5 there was no problem and worked correctly, but under MX 7, the replys.recordcount variable was not found within the cfoutput query="emials" tag.

    The reason I use isdefined is... Depending on conditions, the query "Replys" may or maynot be found on the page. The Replys query only gets created if certain conditions are met.

    The simple fix was to just rename the query.

    Inspiring
    May 3, 2007
    I second Dan's comment - why not just use:

    <cfif myQuery.recordCount gt 0>

    </cfif>

    instead of isDefined("myQuery.recordCount")
    Inspiring
    May 3, 2007
    If I'm understanding correctly, you are trying to test for the number of records in the 'replys' query from within the 'email' output. If you're going to use outputs from both queries, you can use a <cfouput> tag and use the 'email' and 'reply' prefix for the fields. This will allow you to go back and forth.

    <cfoutput>
    #replys.recordcount#
    #email.name#
    </cfoutput>

    If you are testing to see if there are any replies and then wanting to run the results of the 'email' query, wrap the <cfif isdefined> or <cfif #replys.recordcount# gt 0>outside the <cfoutput query=email>. This way, if there are replys, you can process the query, otherwise, perform something else.

    <cfif isdefined("replys.recordcount")>
    <cfoutput query="email">
    blah
    </cfoutput>
    <cfelse>
    There are no replys to display
    </cfif>
    Inspiring
    May 2, 2007
    If you have already run the query, a recordcount will always be defined (for select queries only of course). Why would you be using isDefined?