Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

RecordCount within <CFIF> Statement...

Posted on 2004-04-20
5
Medium Priority
?
784 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
ID: 10869798
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
ID: 10869819
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 200 total points
ID: 10869834
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 200 total points
ID: 10869841
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
ID: 10870029
Thank you both for the help...that was easy, I shoulda picked up on that.  Thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

572 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