• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to show cfelse condition inside a loop?

New Here ,
May 22, 2014 May 22, 2014

Copy link to clipboard

Copied

I have this code:

<table cellpadding="0" cellspacing="0" class="tablecolors">

<h2>Stars Counts</h2>

  <thead><tr><th>Employee</th><th>Stars</th></tr></thead>

  <tbody>

  <cfloop query="GetEmployeeTotals3">

     <cfif GetEmployeeTotals3.csedept_id eq aFieldValue>

  <tr><td>#GetEmployeeTotals3.emp_namefirst# #GetEmployeeTotals3.emp_namelast#</td><td>#GetEmployeeTotals3.employeetotal#</td></tr>

  </tbody>

<cfelse>

<p>no results.</p>

</cfif>

</cfloop>

</table>

Here the query will show the cfelse and the results in the query.

I just cant seem to figure out how i can get it if there are no results in the getemployeetotals3 to not display the table and show 'no results'.

I have try putting in a counter but for some reason it doesn't work and gives me weird results.

Maybe im putting it in the wrong place.

i cant put the cfloop on top because that will just make it loop over and over again.

any ideas on how i can make it work if there are not record in the query?

thanks

Views

202

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2014 May 23, 2014

Copy link to clipboard

Copied

LATEST

<cfif GetEmployeeTotals3.recordcount GT 0>

     <table>

          <!--- etc. --->

     </table>

<cfelse><!--- When there is no data, avoid displaying the table altogether. --->

     <p>No results.</p>

</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation