•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ColdFusion section within the Web Development category of DaniWeb, a massive community of 391,553 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,585 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ColdFusion advertiser:
Views: 2161 | Replies: 2
![]() |
•
•
Join Date: Dec 2006
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
:rolleyes: I am trying to develope a simple application that will record a teams miles per week and total miles I have the code working to accumulate the total, but the problem is how to I get it to accumulate just for the one team and not for all? How do I get it to accumulate for just one team Name? Code is as follows:
Code:
<CFQUERY NAME="Mileage" DATASOURCE="#dsn#">SELECT weeklyMileage, totalMileageFROM mileage</CFQUERY>cfset totalMileage= 0> <cfloop query="Mileage"><cfset totalMileage =totalMileage + Mileage.weeklyMileage></cfloop> <cfquery datasource="#dsn#" dbtype="ODBC"> Insert Into mileage (dateupdated,teamName,teamLeader,email,weeklyMileage,mileageWeekNumber,comments,totalMileage) Values ('#Trim(thetime)#','#Trim(teamName)#','#Trim(teamLeader)#','#Trim(email)#','#Trim(weeklyMileage)#','#Trim(mileageWeekNumber)#','#Trim(comments)#','#Trim(totalMileage)#')</cfquery>
Code:
<CFQUERY NAME="Mileage" DATASOURCE="#dsn#">SELECT weeklyMileage, totalMileageFROM mileage</CFQUERY>cfset totalMileage= 0> <cfloop query="Mileage"><cfset totalMileage =totalMileage + Mileage.weeklyMileage></cfloop> <cfquery datasource="#dsn#" dbtype="ODBC"> Insert Into mileage (dateupdated,teamName,teamLeader,email,weeklyMileage,mileageWeekNumber,comments,totalMileage) Values ('#Trim(thetime)#','#Trim(teamName)#','#Trim(teamLeader)#','#Trim(email)#','#Trim(weeklyMileage)#','#Trim(mileageWeekNumber)#','#Trim(comments)#','#Trim(totalMileage)#')</cfquery>
Missing a where?
SELECT weeklyMileage, totalMileageFROM mileage WHERE teamName=#teamName#
SELECT weeklyMileage, totalMileageFROM mileage WHERE teamName=#teamName#
Google is your friend. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Bored? Visit http://www.kaelisspace.com/
•
•
Join Date: Jan 2007
Location: Austin, TX
Posts: 30
Reputation:
Rep Power: 2
Solved Threads: 0
•
•
•
•
Missing a where?
SELECT weeklyMileage, totalMileageFROM mileage WHERE teamName=#teamName#
You also may want to look into using the GROUP by clause. For example, if your data is as follows:
team, week_nbr, week_miles
A,1,4
A,2,4
A,3,6
B,2,5
C,1,3
C,2,6
You could write a query like:
SELECT team, SUM(week_miles) as total_miles
FROM your_tbl_name
GROUP BY team
Which would return
team, total_miles
A, 14
B, 5
C, 9
Like nikkiH said, you can also use this with a where clause.
Good luck,
Dan
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ColdFusion Marketplace
Similar Threads
- Prog and Logic Question for beginner (Legacy and Other Languages)
- Need help with getting a total for individuals (ColdFusion)
- Help with class methods (Java)
- Classes and using Static member functions to subtotal/total (C++)
- Tapemaking program (Java)
- Problems with displaying total payroll and allowing user to quit by entering a neg. (C++)
- never taught how to show the VAT of a total. I know that u divide by 1.175 (Visual Basic 4 / 5 / 6)
Other Threads in the ColdFusion Forum
- Previous Thread: How to insert data in one column in database?
- Next Thread: Inserting multiple data with cfloop?


Linear Mode