Discussion:
What is wrong with this simple CFIF statement?
(too old to reply)
Yankeet
2009-03-27 16:50:29 UTC
Permalink
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

<cfoutput query="getuser">
<cfif getuser.recordcount IS 1> #getuser.recordcount# records found! ID
#getuser.userID#
<cfelse>
nothing doing !!!
</cfif>
#getuser.recordcount#
</cfoutput>
tclaremont
2009-03-27 17:39:27 UTC
Permalink
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>
Dan Bracuk
2009-03-27 18:10:10 UTC
Permalink
[q][i]Originally posted by: [b][b]tclaremont[/b][/b][/i]
Based strictly on the code you have shown, you do not need the query="getuser"
in your cfoutput tag.
[/q]
Put this:
#getuser.recordcount#

before your cfif tag and you'll see how query="getuser" is messing you up.
Azadi
2009-03-28 10:08:12 UTC
Permalink
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/
BKBK
2009-03-28 19:26:08 UTC
Permalink
<cfoutput query="getuser"> is unnecessary here. In fact, the logic isn't
watertight. There is no need to iterate across the query. The following is
sufficient:

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

Loading...