Skip to main content
Known Participant
May 22, 2014
Question

How to show cfelse condition inside a loop?

  • May 22, 2014
  • 1 reply
  • 261 views

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

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    May 23, 2014

    <cfif GetEmployeeTotals3.recordcount GT 0>

         <table>

              <!--- etc. --->

         </table>

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

         <p>No results.</p>

    </cfif>