ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 28th, 2004, 05:17 PM
mikemac mikemac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Greenville NC
Posts: 70 mikemac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 15 m 24 sec
Reputation Power: 5
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!!!

Reply With Quote
  #2  
Old September 28th, 2004, 05:43 PM
mikemac mikemac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Greenville NC
Posts: 70 mikemac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 15 m 24 sec
Reputation Power: 5
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>

Reply With Quote
  #3  
Old September 28th, 2004, 09:21 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,700 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 17 h 45 m 21 sec
Reputation Power: 53
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

Reply With Quote
  #4  
Old September 29th, 2004, 01:56 PM
mikemac mikemac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Greenville NC
Posts: 70 mikemac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 15 m 24 sec
Reputation Power: 5
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Populating Arrays with <CFLOOP> and DB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT