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 December 23rd, 2004, 10:40 AM
nhrrdan nhrrdan is offline
Coldfusion Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Hampshire
Posts: 62 nhrrdan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 44 m 25 sec
Reputation Power: 5
Send a message via AIM to nhrrdan Send a message via Yahoo to nhrrdan
MySpace Orkut
Question Dynamic Addition with multiple fields

I'm trying to add values together based on a criteria. If an answer is wrong make 0, if its right, make it equal to the weight of the question. Here is the code I have so far.

Code:
<cfoutput query="answers">
  <cfif answers.answer EQ answers.correctanswer>
     <cfset correct = answers.weight>
  </cfif>
	  		
  <cfif answers.answer NEQ answers.correctanswer>
     <cfset wrong = 0 - answers.weight>
  </cfif>

<cfset totalscore = 0>
<cfloop query="answers">
<cfset correctscore = totalscore + correct />
<cfset wrongscore = totalscore + wrong />
</cfloop>

<cfset score = correctscore + wrongscore />

</cfoutput>


Please Help! I am not an expert with coldfusion and I've had no official training. I have no idea if I am going about this right.

Any help would be much appreciated.
__________________
Dan Arsenault
www.dasignz.com
blog.dasignz.com

Last edited by nhrrdan : December 23rd, 2004 at 01:23 PM. Reason: Typo

Reply With Quote
  #2  
Old December 23rd, 2004, 02:02 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,655 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 13 h 29 m 8 sec
Reputation Power: 53
What you're doing (looping over the query twice) and comparing the query's answer (where did that come from?) to the query's correct answer doesn't make sense. Can you explain in more detail what you are trying to do? Is the answer coming from a form?
__________________
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
  #3  
Old December 23rd, 2004, 02:20 PM
nhrrdan nhrrdan is offline
Coldfusion Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Hampshire
Posts: 62 nhrrdan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 44 m 25 sec
Reputation Power: 5
Send a message via AIM to nhrrdan Send a message via Yahoo to nhrrdan
MySpace Orkut
I'm going to display the answers on a page for the user to see which ones were wrong, I also want the page to calculate a grade. Each question has a weight (i.e. 1-5 are worth 10, while 6-15 are worth 5 each) the reason for this is that 1-5 are easier questions and should be known by the test taker.

If the question is wrong I want the value to be a negative of that questions weight (I.e. -10). If the question is correct then I want the weight of the answer to be positive. After all these values are displayed, I then want combine them together. Is there another way to approach this. I tried using the <cfloop> but have had no luck. I hope this is more descriptive and thanks for the response.

Quote:
Originally Posted by kiteless
What you're doing (looping over the query twice) and comparing the query's answer (where did that come from?) to the query's correct answer doesn't make sense. Can you explain in more detail what you are trying to do? Is the answer coming from a form?

Reply With Quote
  #4  
Old December 23rd, 2004, 03:38 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,655 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 13 h 29 m 8 sec
Reputation Power: 53
But where are the user's answers coming from? A form? The query?

Reply With Quote
  #5  
Old December 23rd, 2004, 06:23 PM
nhrrdan nhrrdan is offline
Coldfusion Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Hampshire
Posts: 62 nhrrdan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 44 m 25 sec
Reputation Power: 5
Send a message via AIM to nhrrdan Send a message via Yahoo to nhrrdan
MySpace Orkut
I'm sorry, they are coming from a query of an Access database table.

Quote:
Originally Posted by kiteless
But where are the user's answers coming from? A form? The query?

Reply With Quote
  #6  
Old December 30th, 2004, 08:41 AM
nhrrdan nhrrdan is offline
Coldfusion Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Hampshire
Posts: 62 nhrrdan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 44 m 25 sec
Reputation Power: 5
Send a message via AIM to nhrrdan Send a message via Yahoo to nhrrdan
MySpace Orkut
Question

I've simplified things a bit.

I want to add up all the wrong values and subtract it from the total possible score. I am looping through a query of the database. I can't seem to get it to work, I have no Idea how to add up the wrong values in the line marked with **. All I get is the last value the loop generates, instead of adding up the values. I know how to use aggregate functions in the SQL query, but is this possible? Or, is there something I have to do with an array? Someone please help.

Code:
<cfloop query="answers">
<cfif answers.answer NEQ answers.correctanswer>

<cfset wrong = 0 - #answers.weight#>
**<cfset totalwrong = ???????????>

</cfif>
</cfloop>

Reply With Quote
  #7  
Old December 30th, 2004, 09:41 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,655 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 13 h 29 m 8 sec
Reputation Power: 53
Are you looking for something like this:

<cfset totalWrong = 0 />
<cfloop query="answers">
<cfif answers.answer NEQ answers.correctanswer>
<cfset wrong = 0 - #answers.weight# />
<cfset totalWrong = totalWrong + wrong />
...

Reply With Quote
  #8  
Old January 10th, 2005, 08:34 AM
nhrrdan nhrrdan is offline
Coldfusion Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Hampshire
Posts: 62 nhrrdan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 44 m 25 sec
Reputation Power: 5
Send a message via AIM to nhrrdan Send a message via Yahoo to nhrrdan
MySpace Orkut
Smile

Sorry for the delay on replying. I was on vacation last week and didn't use a computer for the entire week. I haven't tried your recomendation yet, but I will give it a shot. I appreciate your response. Thank you.

Quote:
Originally Posted by kiteless
Are you looking for something like this:

<cfset totalWrong = 0 />
<cfloop query="answers">
<cfif answers.answer NEQ answers.correctanswer>
<cfset wrong = 0 - #answers.weight# />
<cfset totalWrong = totalWrong + wrong />
...

Reply With Quote
  #9  
Old January 10th, 2005, 08:43 AM
nhrrdan nhrrdan is offline
Coldfusion Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Hampshire
Posts: 62 nhrrdan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 44 m 25 sec
Reputation Power: 5
Send a message via AIM to nhrrdan Send a message via Yahoo to nhrrdan
MySpace Orkut
Thumbs up Thanks, I appreciate it!!!

I just tried plugging that in to my code and it worked. Thank you very much, you have saved me quite a bit of time.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Dynamic Addition with multile fields


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 1 hosted by Hostway