views:

145

answers:

1

Hey, i am simple cart page where it displays the content in table form and I am trying to find a way to add up the Cost column then display the total price at the bottom. Does anyone have any suggestions how to do that? The part that is confusing me is that it the table is dynamically created via ASP.

My code can be found here: http://pastie.org/341676

Any suggestions?

Thanks so much,

Ryan

+3  A: 

First off, that is a special kind of painful (asp classic in all its glory)

What you need is another variable to hold your values, and then sum it in each loop iteration

While Not objRS.EOF
    totalCost = trim(objRS.Fields("quantity"))*trim(objRS.Fields("p_price"))
    absoluteTotal = absoluteTotal + totalCost

...

Wend

Response.Write absoluteTotal

That will output a sum of all the totals, although you would probably want to format it better with html and whatnot

Matt Briggs
Perfect...thank you very much Matt! It worked great.RYan
Coughlin
Glad to have been of help :)
Matt Briggs
How is that more painful than... well, any other programming language? There might be some that come with some nice way that wraps that up for you, but if they don't you'll be using a loop and add to a variable. (Or not?)
Tomalak
I was talking about ASP classic in a general way
Matt Briggs
Elegance of code is as much a tribute to the skill of the developer as to the fundamental syntax of the language. ASP can be elegant and easily read when used by someone with the care to do it properly.
Cirieno