Solved

RecordCount within <CFIF> Statement...

Posted on 2004-04-20
5
764 Views
Last Modified: 2013-12-24
Do recordcount commands work inside <CFIF> statements?  I'm trying to just list people who have birthdays each day...but if there are no records queried for a birthday on a day, I want it to display we have no birthdays.  Today for instance, we have nothing in the dbase with an 04/20 birthdate, so the query should have a recordcount of 0...so in my CFOUTPUT I have put if the recordcount = 0 to display "we have no celebrations today" ELSE display the names.  Does this not work this way???

<!-- BEGIN QUERY SECTION -->
<cfset TodayDate = DateFormat(Now(), "M/D")>

<CFQUERY datasource="myds" name="birthday" blockfactor="100">
      SELECT *
      FROM tbl_personal, tbl_employees
      WHERE tbl_employees.EmployeeID = tbl_personal.EmployeeID
            AND (tbl_personal.Birthdate = ###TodayDate###)
      ORDER BY tbl_employees.SortName asc
</CFQUERY>
<!-- END QUERY SECTION -->
Birthday Celebrations...<br>
<br>
<CFSET Count=#birthday.recordcount#>
<cfoutput query="birthday">
<CFIF #count# EQ 0>
There are no birthday celebrations on this day...
<CFELSE>
#FirstName# #LastName#<br>
</cfif>
</cfoutput>
0
Comment
Question by:Lee R Liddick Jr
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:PE_CF_DEV
Comment Utility
the way you have it will not work b/c the cfoutput will only loop through the birthdays so the if statement will not execute. You'll want to change it to:

<CFIF #count# EQ 0>
   There are no birthday celebrations on this day...
<CFELSE>
   <cfoutput query="birthday">
       #FirstName# #LastName#<br>
    </cfoutput>
</cfif>

0
 
LVL 15

Expert Comment

by:tim_cs
Comment Utility
You should be able to just do...
<CFIF birthday.recordCount>
#FirstName# #LastName#<br>
<CFELSE>
There are no birthday celebrations on this day...
</cfif>
0
 
LVL 6

Assisted Solution

by:PE_CF_DEV
PE_CF_DEV earned 50 total points
Comment Utility
Also on a side note in CF you can just use recordcount as a boolean value and evaluate it like this

<CFIF birthday.recordcount>
   <cfoutput query="birthday">
       #FirstName# #LastName#<br>
    </cfoutput>
<CFELSE>
   There are no birthday celebrations on this day...
</cfif>

Also notice you do not need the pound sign in the CFIF statement. The If statement will evaluate as TRUE so long as the variable is an integer that is not 0.
0
 
LVL 15

Accepted Solution

by:
tim_cs earned 50 total points
Comment Utility
and like he said above make sure you have your cfoutputs inside.

<CFIF birthday.recordCount>
<cfoutput query="birthday">
#FirstName# #LastName#<br>
</cfoutput>
<CFELSE>
There are no birthday celebrations on this day...
</cfif>
0
 

Author Comment

by:Lee R Liddick Jr
Comment Utility
Thank you both for the help...that was easy, I shoulda picked up on that.  Thanks!
0

Featured Post

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now