0

I'm a little lost checking if an answer list has all "N/A" (Not Applicable) responses in it. If so - I want it to display "All Chosen as NOT Applicable"

Code below works if all answers are N/A - but if there is a Yes or No in there. It may also show the All Chosen as NOT Applicable note...

I'm thinking it is in my first CFLOOP where I need to make sure it is set properly to all not applicable... But it doesn't go thru all the query answers first... And if it hits an N/A it will stick a all not applicable in there...

Brain hurts trying to fix... Probably something silly and simple...

<cfquery name=qlist datasource="#mhhds#">
    select * from question where catid = #catid# and specific = 0
    order by catid
</cfquery>

<cfloop query=qlist>
    <cfquery name="anslist" datasource="#mhhds#">
        select * from Answer where inspid = #inspid# and qid = #qid#
        order by qid
    </cfquery>

    <cfparam name="ansnotna" default="">
    <cfif anslist.answer contains "yes" or anslist.answer contains "no">
        <cfset ansnotna = "yes">
    <cfelse>
        <cfset ansnotna = "na">
    </cfif>
</cfloop>

<cfif ansnotna is "na">
    <div class="nalist">
        <span  class=verd10>All Chosen As Not Applicable</span>
    </div>
</cfif>


<cfloop query=qlist>
    <cfquery name="anslist" datasource="#mhhds#">
        select * from Answer where inspid = #inspid# and qid = #qid#
        order by qid
    </cfquery>

    <cfif anslist.answer is Not "N/A">
        Show N/A Stuff
    </cfif>

    <cfif anslist.answer is "Yes">
        Show Yes Stuff
    </cfif>

    <cfif anslist.answer is "No">
        Show No Stuff
    </cfif>
</cfloop>

Got it sorted... Created a list and appended list each time... If it contains a yes or no - it can't be "All not Applicable"

      <cfset alist = "">

      <cfloop query=qlist>
      <cfquery name="anslist" datasource="#mhhds#">
      select * from Answer where inspid = #inspid# and qid = #qid#
      order by qid
      </cfquery>

      <cfset alist = ListAppend(alist, "#anslist.answer#", ",")>

      </cfloop>

      <cfparam name="nalist" default="yes">
      <cfif alist contains "yes" or alist contains "no">
      <cfset nalist = "no">
      </cfif>

      <cfif nalist is "yes">
      <div class="nalist">
      <span  class=verd10>
      All Chosen As Not Applicable
      </span>
      </div>
Merle_the_Pearl
  • 1,391
  • 3
  • 18
  • 25
  • 6
    You need to completely rethink this. Instead of doing one query for the questions, then another to get all the answers for each question, just have one query that joins the questions and answers. Also avoid using `SELECT *`, and you should use `` for your dynamic query parameters – duncan Feb 04 '14 at 17:01
  • 4
    *You need to completely rethink this* Especially if you are storing delimited lists of values, as the variable names and code suggest ... [That is a very bad idea](http://stackoverflow.com/a/3653574/104223). – Leigh Feb 04 '14 at 17:10

0 Answers0