Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

RecordCount within <CFIF> Statement...

Posted on 2004-04-20
5
Medium Priority
?
781 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 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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

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…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

618 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