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
Solved

RecordCount within <CFIF> Statement...

Posted on 2004-04-20
5
768 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 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to enable php7 module in nginx configuration file 8 455
assigning port numbers to web sites and web services 2 78
AWS Advice on using WHM/cPanel 1 79
System Analysis 5 61
This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

789 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