Simone
03/19/2022, 8:25 PM<cffunction name="getCorrectAnswer" returntype="any" output="true" hint='Gets the correct answer'>
<cfargument name="questionidfk" type="UUID" required="true">
<cfset var rsQuery=querynew('')>
<cfset var answer = ''>
<cfquery name="rsIdfromQuestion" datasource="#variables.dsn#">
select id
from questions
where questionnaireidfk = <cfqueryparam value="#arguments.questionidfk#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
</cfquery>
<cfloop query="rsIdfromQuestion">
<cfquery name="rsQuery" datasource="#variables.dsn#">
select correctAnswer,rank,answer,a_id,id,ROW_NUMBER() OVER(ORDER BY id ASC) AS Row
from answers
where questionidfk = <cfqueryparam value="#rsIdfromQuestion.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
AND correctAnswer IS NOT NULL
</cfquery>
<cfset answer = request.udf.ParagraphFormat2(rsQuery.answer)>
<cfreturn answer>
</cfloop>
</cfif>
</cffunction>
Adam Cameron
</cfif>
, but no opening one.
When you say "not picking up the value", which value? What debugging have you put in here (like <cfdump>
) to check values are what you expect them to be.
Have you dumped out rsIdfromQuestion
and each rsQuery
to see what yer getting?
NB: you are `var`ing a coupla variables, but you've forgotten to do rsIdfromQuestion
;-)Adam Cameron
looks like a loop problem but can't be sureOf course you can be sure. How many times should it be looping, and how many times is it looping? You can check all this stuff. There doesn't need to be any mystery to it.
Simone
03/19/2022, 8:41 PMMichael Schmidt
03/21/2022, 4:45 PMselect q.id as QuestionID, correctAnswer,rank,answer,a_id,a.id,ROW_NUMBER() OVER(ORDER BY a.id ASC) AS Row
from questions q
inner join answers a on q.id = a.questionidfk and a.correctAnswer is not null
where questionnaireidfk = <cfqueryparam value="#arguments.questionidfk#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
Let your DBMS do what it is good at joining and handling Set Data.