Forums

This topic is locked

Add fields together (e-commerce "Qty" Issue)

Posted 30 Oct 2002 22:41:12
1
has voted
30 Oct 2002 22:41:12 Peter Lent posted:
Hi All,

I have a ecommerce site I am working on and the shipping is based on total items. I have a qty field in my cart table. What I am trying to do is calculate (add up) all of the QTYs that appear.

The trouble I am having is because it is the same field I am trying to add up. I cannot figure how to "repeat" the addition.

Any suggestions?

THANKS

Peter

Replies

Replied 30 Oct 2002 23:19:52
30 Oct 2002 23:19:52 Ned Frankly replied:
Is this a custom cart using a table in a database, or a session-based cart?



Ned Frankly
www.nedfrankly.com
You think I ramble on HERE?
Replied 30 Oct 2002 23:37:40
30 Oct 2002 23:37:40 Peter Lent replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Is this a custom cart using a table in a database, or a session-based cart?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

This is a custom cart, however is uses a DB table called "cart" to store the users "order" in based on session.

The checkout page gathers all the items for the person by session.sessionID

THANKS

Peter
Replied 31 Oct 2002 06:02:00
31 Oct 2002 06:02:00 Ned Frankly replied:
Simple SUM (total qty for the entire order) would be

SELECT SUM(Qty) AS TotalQty from cart
WHERE order = varSessionID
GROUP BY order

varSessionID is set to your Session value.

Ned Frankly
www.nedfrankly.com
You think I ramble on HERE?
Replied 31 Oct 2002 06:05:10
31 Oct 2002 06:05:10 Ned Frankly replied:
The profanity filter got me again. I shouldn't try to use the word a-r-s-e, even when it's part of a word like p-a-r-s-e, or even worse, v-a-r-S-e-s-s-i-o-n-I-D, which is the word that shows as varSessionID above...

I can still say ASSESS, though...

Ned Frankly
www.nedfrankly.com
You think I ramble on HERE?
Replied 31 Oct 2002 17:51:47
31 Oct 2002 17:51:47 Peter Lent replied:
Ok, I am a little lost. Still being pretty green with ASP, I cannot get this to work. I am getting an error on the entire page. it has something to do with the "Sum" issue.

Also, how would I display the result or use the result in another function?

THANKS

-Peter

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
The profanity filter got me again. I shouldn't try to use the word a-r-s-e, even when it's part of a word like p-a-r-s-e, or even worse, v-a-r-S-e-s-s-i-o-n-I-D, which is the word that shows as varSessionID above...

I can still say ASSESS, though...

Ned Frankly
www.nedfrankly.com
You think I ramble on HERE?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 01 Nov 2002 20:12:50
01 Nov 2002 20:12:50 Ned Frankly replied:
You have to set a temporary variable to your session value, then use that temporary variable in the query either as a WHERE or in the GROUP BY as a HAVING. I didn't mean for you to use the query I provided verbatim - it is a guideline for the syntax required to get a sum of a single column grouped by another column.

The idea is to group by the one common element - the session id - and get a sum of all quantities, unless I misread your intent. If you will provide the exact table name, column names, name of your session variable and which column in your table that equates to, I'll give you the exact query to use.

Your second question - you use it just as you'd use any other recordset value. It's a column in a table after the query executes.

Ned Frankly
www.nedfrankly.com
You think I ramble on HERE?
Replied 01 Nov 2002 20:21:15
01 Nov 2002 20:21:15 Peter Lent replied:
Here is the information

Table Name: cart
Session Variable Name: cartID
column names in Table CART
cart_id (stores session var info)
prod_id (product id number)
prod_name (product name)
prod_color (product color)
prod_price (product price)
quantity (quantity ordered, this is the one I am trying to add up)

I think that is it.

THANKS!!!!!

Peter


<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
If you will provide the exact table name, column names, name of your session variable and which column in your table that equates to, I'll give you the exact query to use.

Your second question - you use it just as you'd use any other recordset value. It's a column in a table after the query executes.

Ned Frankly
www.nedfrankly.com
You think I ramble on HERE?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 01 Nov 2002 20:37:20
01 Nov 2002 20:37:20 Ned Frankly replied:
Do a standard recordset with the following query and temporary variable (you shouldn't need the GROUP BY):

Recordset: rsTotalQuantity

SELECT SUM(quantity) AS TotalQty
FROM cart
WHERE cart_id = varCartID

Temporary variable (Name, default value, runtime value):
varCartID, 0, Session("cartID"

Refer to it whereever you need it as
&lt;%=(rsTotalQuantity.Fields.Item("TotalQty".Value)%&gt;

Ned Frankly
www.nedfrankly.com
You think I ramble on HERE?

Reply to this topic