Solved

RecordCount within <CFIF> Statement...

Posted on 2004-04-20
5
772 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 50 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 50 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

724 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