Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coldfusion Recordcount Problem

Status
Not open for further replies.

wlg1477

Programmer
Joined
Feb 18, 2003
Messages
2
Location
GB
I have been staring at this for hours, and simplified the code to the essence of the problem. I basically run a query which works fine when there the recordcount is not 0. Although, if there are no records found, the page comes up blank... rather than "The recordcount is 0!" I would greatly appreciate any assistance.



<cfquery name=&quot;OldUserName&quot; datasource=&quot;Teak&quot; dbtype=&quot;ODBC&quot;>
SELECT SCPid, UserName
FROM tblSalesCommissionPayees
WHERE Username='#Form.UserNameAdd#'
</cfquery>


<cfoutput query=&quot;OldUserName&quot;>
<cfif #oldusername.RecordCount# eq 1>
The Recordcount is 1!
<cfelse>
The recordcount is 0!
</cfif>
</cfoutput>
 
if you just want to check how many records have been returned then you don't need to surround the if statement with the 'cfoutput query=&quot;OldUserName&quot;'

if you want to set some values at a later stage, based on if the username was found in the database then you can use this:

<cfif oldusername.RecordCount eq 1>
<CFSET a = OldUserName.SCPid>
<CFSET b = OldUserName.UserName>

The Recordcount is 1!
<cfelse>
The recordcount is 0!
</cfif>

Also not that in the CFIF statement we don't need to use the # around the recordcount, as we are within a CF tag.

hope this helps!

Tony
 
Thanks Tony. Worked beautifully! I was really hoping it was just a syntax problem.

Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top