Search code examples
coldfusioncoldfusion-10

Trouble with If Statements to fully loop and not fully loop


What I am trying to do is if pcount is = 0

<cfif (isDefined("session.checkout.quantity.pcount")) eq 0>

then loop this but skip the last loop

    <cfif BAdd NEQ session.checkout.quantity.bcount>
         <cfinclude template="../../../ddl/bandor.cfm">

and if pcount is not equal to 0 (zero is the number 0 in a drop down menu not just blank)

<cfif (isDefined("session.checkout.quantity.pcount")) neq 0>

then loop this everytime

<cfinclude template="../../../ddl/bandor.cfm">

This is the full code if anyone can please tell me what I am doing wrong?

<cfif (isDefined("session.checkout.quantity.pcount")) eq 0>
  <cfif BAdd NEQ session.checkout.quantity.bcount>
    <cfinclude template="../../../ddl/bandor.cfm">
  </cfif>
</cfif>
<cfif (isDefined("session.checkout.quantity.pcount")) neq 0>
  <cfinclude template="../../../ddl/bandor.cfm">
</cfif>  

Solution

  • <cfif structKeyExists(session.checkout.quantity, "pcount") AND session.checkout.quantity.pcount eq 0>
      <cfif BAdd NEQ session.checkout.quantity.bcount>
        <cfinclude template="../../../ddl/bandor.cfm">
      </cfif>
    <cfelse>
      <cfinclude template="../../../ddl/bandor.cfm">
    </cfif>