Question

I am displaying results in a table after looping through a query. For TestNumber, there are some results in my query where the number is not present and hence I want to display N/A instead of just blank in the table. So, I am checking the existence using IsDefined, but for some reason it keeps on printing N/A everytime.

<cfloop query="GetMyList1">
    <tr>
        <td align="center">#TestName#</td>
        <cfif IsDefined(TestNumber) >
            <td align="center">#TestNumber#</td>
        <cfelse>
            <td align="center">N/A</td>
        </cfif>
        <td align="center">#Date#</td>
    </tr>
</cfloop>
Was it helpful?

Solution

You would want to check if there is a length of the item. The field exists, so isDefined will always return true

<cfloop query="GetMyList1">
  <tr>
    <td align="center">#GetMyList1.TestName#</td>
    <td align="center"><cfif len(trim(GetMyList1.TestNumber))>#GetMyList1.TestNumber#<cfelse>N/A</cfif></td>
    <td align="center">#GetMyList1.Date#</td>
  </tr>
</cfloop>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top