|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Populating Arrays with <CFLOOP> and DB
OK I have a database with a question tablle. I would like to do a CFQUERY and retrive the "Question" field. (I can do that!!) Then I would Like to assign each "question" to an individual element in a CFLOOP. Then what I'll be doing is somehow rndomly selecting elements in the array to create a Question bank of predefined size for individual tests. Basically what I am doing is creating an online testing center as part of my semester project. Here is my wrong take on this process.
---------------------------------------------------------------- <CFQUERY NAME="Questions" DATASOURCE="TestCenter" SELECT Questions FROM PossibleQues </CFQUERY> <CFSET ques=ArrayNew(1)> <CFLOOP FROM="1" TO="#Questions.RECORDCOUNT#" index="i"> <CFSET ques[i]="#Questions#"> </CFLOOP> ------------------------------------------------------------- What am I doing wrong. I am taking a ColdFusion MX class on campus and have decided that I'm going to use CF for my Internship, man have I got a lot to learn. Any help is most appreciated!!! |
|
#2
|
|||
|
|||
|
UPDATE---->
I have populated the array with the contents of the table. But, it diplays the first question from the DB and repeats it in the output. It is like "i" never increments to let ques[2] or ques[3] or ques[4] or ques[5] display. here is the output I receive in the browser when executing my code: 1+2=? 1+2=? 1+2=? 1+2=? 1+2=? See how it repeats the first entry!!!!
---Below is the code I used to obtain that erroneous output--- <CFQUERY NAME="QuesBank" DATASOURCE="ALC"> SELECT Question FROM MathQB1T1 </CFQUERY> <CFSET ques=ArrayNew(1)> <CFLOOP FROM="1" TO="#QuesBank.RECORDCOUNT#" index="i"> <CFSET ques[i]=#QuesBank.Question#> </CFLOOP> <CFSET quesLen=ArrayLen(ques)> <CFLOOP FROM="1" to="#quesLen#" index="i"> <CFOUTPUT>#ques[i]# <CFSET i = i+1> </CFOUTPUT> </CFLOOP> |
|
#3
|
|||
|
|||
|
What about just doing a query loop or a cfoutput?
<cfset myArray = arrayNew(1) /> <cfloop query="quesBank"> <cfset arrayAppend( myArray, quesBank.question ) /> </cfoutput> Also, is there a real reason why you need this in an array and can't just use it as a query result object?
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#4
|
|||
|
|||
|
Hers the deal
What I am eventually gonna do is:
Populate the array with test question Populate another array with 3 test incorrect answers Also create one answer that is correct that corresponds to the appropriate question. Basically create a multiple choice exam with 4 answers to choose from one being correct. Last edited by mikemac : October 2nd, 2004 at 12:52 PM. Reason: pooped |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Populating Arrays with <CFLOOP> and DB |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|