billybrag
Jun 5th 2006, 5:40 am
Hello,
I am trying to get some info from 2 database tables using an array and i need to , effectivly, store an array in an array.
I think this is called a 2 dimensional array.
Here is the code so you can see what im doing..
<!--- start old poll displays--->
<!--- Get all the questions--->
<cfquery name="qgetpolls"
datasource="#dsn#">
SELECT * FROM question
where isactive=1
</cfquery>
<!--- count the number of questions--->
<cfoutput>
<cfset numpolls = #qgetpolls.recordcount#>
</cfoutput>
<!--- Grab all of the questions--->
<cfloop from="1" to="#numpolls#" index="i">
<cfset polls[i ] = StructNew()>
<cfset polls[i ].question = #qgetpolls.question[i ]#>
<cfset polls[i ].id = #qgetpolls.questionid[i ]#>
<!--- using the id above get the matching answers from the answer table--->
<cfquery datasource="#dsn#" name="getnumanswers"> SELECT * FROM answer
WHERE questionid = #polls[i ].id#
</cfquery>
<cfset numanswers = #getnumanswers.recordcount#>
<!--- loop through and get all of the answers--->
<cfloop from="1" to="#numanswers#" index="a">
<cfset pollanswers[a] = StructNew()>
<cfset pollanswers[a].answer =#getnumanswers.answer[a]#>
</cfloop>
<!--- How do i store the above pollanswers[a].answer in the polls array--->
</cfloop>
can anyone help me do what i want, i think i have explained it correctly
thanks
I am trying to get some info from 2 database tables using an array and i need to , effectivly, store an array in an array.
I think this is called a 2 dimensional array.
Here is the code so you can see what im doing..
<!--- start old poll displays--->
<!--- Get all the questions--->
<cfquery name="qgetpolls"
datasource="#dsn#">
SELECT * FROM question
where isactive=1
</cfquery>
<!--- count the number of questions--->
<cfoutput>
<cfset numpolls = #qgetpolls.recordcount#>
</cfoutput>
<!--- Grab all of the questions--->
<cfloop from="1" to="#numpolls#" index="i">
<cfset polls[i ] = StructNew()>
<cfset polls[i ].question = #qgetpolls.question[i ]#>
<cfset polls[i ].id = #qgetpolls.questionid[i ]#>
<!--- using the id above get the matching answers from the answer table--->
<cfquery datasource="#dsn#" name="getnumanswers"> SELECT * FROM answer
WHERE questionid = #polls[i ].id#
</cfquery>
<cfset numanswers = #getnumanswers.recordcount#>
<!--- loop through and get all of the answers--->
<cfloop from="1" to="#numanswers#" index="a">
<cfset pollanswers[a] = StructNew()>
<cfset pollanswers[a].answer =#getnumanswers.answer[a]#>
</cfloop>
<!--- How do i store the above pollanswers[a].answer in the polls array--->
</cfloop>
can anyone help me do what i want, i think i have explained it correctly
thanks