Skip to main content
Inspiring
March 27, 2009
Question

What is wrong with this simple CFIF statement?

  • March 27, 2009
  • 4 replies
  • 823 views
Hi, I've included a simple cfif statment to check to see if a user is already in the database, for some reaons the <cfelse> part of the statement does not work. that is, if the user is there it returns the recordcount and ID etc. but if it is a new user (no records found) it is just blank (without the nothing doing !!!) any ideas?

Thanks
Yankee
    This topic has been closed for replies.

    4 replies

    BKBK
    Community Expert
    Community Expert
    March 28, 2009
    <cfif getuser.recordcount GT 0>
    <cfoutput>#getuser.recordcount# records found! ID #getuser.userID#</cfoutput>
    <cfelse>
    nothing doing !!!
    </cfif>

    Inspiring
    April 13, 2009

    I will make it as

    <cfif getuser.recordcount> 
          <cfoutput>#getuser.recordcount# records found! ID #getuser.userID#</cfoutput>
    <cfelse>
          nothing doing !!!
    </cfif>

    Inspiring
    March 28, 2009
    yours is a mistake many fall for: when your getuser query returns 0
    records, your <cfoutput query="getuser"> does not execute - it has
    nothing to output.
    no code is executed inside a query-based cfoutput when that query is empty.


    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Inspiring
    March 27, 2009
    You're right Dan, <cfoutput> should've been without the query="getuser" thanks
    tclaremont
    Inspiring
    March 27, 2009
    Based strictly on the code you have shown, you do not need the query="getuser" in your cfoutput tag.

    Also, I would check to see if the value is greater than zero rather than equal to one. What if the person has more than one record in the database?

    Try this...

    <CFIF getuser.recordcount GT 0>
    #GetUser.RecordCount# Records Found
    <CFELSE>
    Doing Nothing
    </CFIF>
    Inspiring
    March 27, 2009
    quote:

    Originally posted by: tclaremont
    Based strictly on the code you have shown, you do not need the query="getuser" in your cfoutput tag.


    Put this:
    #getuser.recordcount#

    before your cfif tag and you'll see how query="getuser" is messing you up.