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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old February 19th, 2008, 11:20 AM
Spudster105 Spudster105 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 9 Spudster105 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 43 m 33 sec
Reputation Power: 0
Adding records together

Hello all, long time reader, first time poster ( finally registered on here lol )

Here is the problem I am having.

I have build a shopping carts of sorts that stores the input into session variables based on part numbers (ie PN01, PN02, etc) After the person goes all the way through the form at the end, it shows them the product number they have built based on the choices they have made. Example PN01 = T, so if during the form they picked PN01, the product number will have T in it. So all of that works great and fine but where I am running into trouble is that I want to get them a price based on the product number they made. I already have in the DB the price for each product number and it is working. I can pull PN01 from the db, which is T, and it costs 400 bucks. So it is pulling the right info but I dont know how to add the different numbers together. Say there product number is T 0 1 0 1 L 1 - D D - I D D...It should go find the cost of PN01, which equals T, then go to PN02 which equals 0, so on and so forth, and add them all together for one big fat price...but I am stuck. Here is the code that I am using to select the price from the db based on the part number:

Code:
<cfquery datasource="#db#" name="getPrice">
select price from pricing a
left join pricing_cats b on
a.cat=b.name
 where a.type = 2
and a.designator ='#session.PN01#'
</cfquery>

Then to display the price I have

Code:
<cfoutput>
#getPrice.price#
</cfoutput>


The pricing table has the price, and the designator(product number) for each part and the pricing_cats just has the type for sorting purposes. Let me know if anyone has any ideas or needs me to explain something else, its pretty confusing and i wrote it lol

Thanks

Adam
//cyberjaz.net

Reply With Quote
  #2  
Old February 19th, 2008, 12:53 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,727 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 19 h 22 m 42 sec
Reputation Power: 848
SELECT SUM(price) AS total_price FROM ...
__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old February 19th, 2008, 01:00 PM
Spudster105 Spudster105 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 9 Spudster105 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 43 m 33 sec
Reputation Power: 0
Quote:
Originally Posted by r937
SELECT SUM(price) AS total_price FROM ...




Like This?
Code:
<cfquery datasource="#db#" name="getPrice">
select sum(price) as total_price from pricing a left join 
pricing_cats b ona.cat=b.name
 where a.type = 2 and a.designator
 '#session.PN01#'</cfquery><cfoutput>
#getprice.total_price#</cfoutput>


This is what I get:
The sum or average aggregate operation cannot take a varchar data type as an argument.

So change varchar to int?


Also there has to be more then just
a.designator '#session.PN01#'
I have up to PN18 that need checked and added

Reply With Quote
  #4  
Old February 19th, 2008, 01:13 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,727 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 19 h 22 m 42 sec
Reputation Power: 848
change VARCHAR to DECIMAL(7,2)

Code:
... and a.designator IN 
      ( '#session.PN01#'
      , '#session.PN02#'
      ...
      , '#session.PN18#' )

Reply With Quote
  #5  
Old February 19th, 2008, 01:27 PM
Spudster105 Spudster105 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 9 Spudster105 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 43 m 33 sec
Reputation Power: 0
Code:
<cfquery datasource="#db#" name="getPrice">select sum(price) as total_price from pricing a
left join pricing_cats b on 
a.cat=b.name where a.type = 2
and a.designator IN(
'#session.PN01#'
,'#session.PN02#'
,'#session.PN03#'
)</cfquery><cfoutput>		$#getprice.total_price#</cfoutput>



With the following code I am only getting the total of PN01 which is 400 bucks. PN02 and PN03 both have money values in them but they arent adding in with the first number


thanks for your help thus far

Reply With Quote
  #6  
Old February 19th, 2008, 01:30 PM
Spudster105 Spudster105 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 9 Spudster105 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 43 m 33 sec
Reputation Power: 0
never mind!!! I wasn't redoing the whole form, so it was erasing the sessions and just keeping the last page, which is PN01....so there was nothing else to add to the number. thanks a ton!!!

Reply With Quote
  #7  
Old February 19th, 2008, 02:54 PM
Spudster105 Spudster105 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 9 Spudster105 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 43 m 33 sec
Reputation Power: 0
so I guess I spoke too soon and its not doing what I need it to. Its not adding all of the numbers together. Its only adding some of them for whatever reason ( happens to just be the 2 highest prices, 800 and 400 ) so i keep getting 1200 for my final price and it should be much higher then that.

Ill paste the code again

Code:
<cfquery datasource="#db#" name="getPrice2">
select sum(price) as total_price from pricing a
left join pricing_cats b on
a.cat=b.name
where a.type = 2
and a.designator IN(
'#session.PN01#'
,'#session.PN02#'
,'#session.PN03#'
,'#session.PN04#'
,'#session.PN05#'	
,'#session.PN06#'	
,'#session.PN07#'
,'#session.PN09#'
,'#session.PN10#'
,'#session.PN12#'
,'#session.PN13#'
,'#session.PN14#'
,'#session.PN15#'
,'#session.PN17#'
,'#session.PN18#'
)</cfquery><cfoutput>
$#getprice2.total_price#.00
</cfoutput>

Reply With Quote
  #8  
Old February 20th, 2008, 12:47 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,727 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 19 h 22 m 42 sec
Reputation Power: 848
for me to understand what's happening, i'd have to know a lot more about your tables and what's in 'em

perhaps you could show a few sample rows from each table, and show what result you expect the query to produce


Reply With Quote
  #9  
Old February 20th, 2008, 12:54 PM
Spudster105 Spudster105 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 9 Spudster105 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 43 m 33 sec
Reputation Power: 0
Quote:
Originally Posted by r937
for me to understand what's happening, i'd have to know a lot more about your tables and what's in 'em

perhaps you could show a few sample rows from each table, and show what result you expect the query to produce



well I actually figured everything out.

Whenever someone makes a selection, the value gets stored in the session, which also relates to an entry in my db. For example, if someone picks a yes option for PN10, in the DB PN10 cost XX amt of money. So at the end, where i was having problems, is that i needed to concat some part numbers before i added anything. Like pn10 = 4 and pn11 =5 and in the other table in the db 45= something...but 4 and 5 by themselves dont mean anything. So i combined the parts that needed combined first, THEN, added everything together. still confusing to explain, but everything works and im pumped!!! lol

thanks for your help, really appreciate it!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Adding records together


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway