Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Totalling Form values 1

Status
Not open for further replies.

Shilohcity

Technical User
Jul 12, 2000
136
GB
Hello

I am trying to wrap my head around this problem. I have a page with various items quantities and prices on it populated from a database. They are all individually named by using a looping identifier and are passed to a page where the user can confirm their selections and see a total price. I have the page displaying the selection fine along with the prices but how do I get a totalprice?

I have tried something like:

records = Request(records)'total records on previous page
id = 0

Do while records > id
If id = 0 Then
price0 = Request("itemprice")
id = id + 1
ElseIf id = 1 Then
price1 = Request("itemprice")
id = id + 1
Loop

Response.Write "totalprice = (price0 + price1 + etc..)"


Now this is a far from perfect way of doing things so does anybody have any suggestions of ways to do this?

Cheers
Justin
 
Can run a second sql to get the total and use that? This should be quicker then adding them all up.

Mark
 
Hmmmm....

Im not sure I get what you mean. Are you thinking maybe I could use an SQL query to match products selected and their prices from the productinfo table and then total them maybe something like this?

SQL = TOTAL itemprice WHERE itemid IN (&itemid&)

Justin.

 
Maybe I don't understand how you recieved the info from the query that filled your form. If you used an SQL you should be able to run an SQL using the same criteria to build the sum. If you did a do while.. loop, you should be able to add the total at the same time as you are looping through the items.

ttl = ttl + (quantity * price)

Mark
 
okay I think I have it under control now....so

on the order page I am grabbing values from a table and then passing these to the confirmation page so on the confirmation page I use:

Do While Not objRS.EOF
quantity = Request("quantity")
price = Request("price")
total = total + (price*quantity)
Loop

Response.Write total


Cool I will test this out and let u know how it goes

Thanks for your help in clearing my thoughts on this.

Justin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top