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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop inside a loop

Status
Not open for further replies.

lynque

IS-IT--Management
Sep 30, 2004
124
CA
Hello all,

I first want to say that this site and it's patrons have been incredibly helpful and an invaluable resource, thanks tek-tips

I have a for loop which inserts data fine, the problem is that the variables in the loop can contain more than one item (i.e. multiple items in one order).

Currently it will insert the data it collects on it's last run through...

here is the code

Code:
for each item in Request.form("strOrderItem")
  strOrderItem = cstr(item)
  itemInfo = split(strOrderItem, ",")
  rsItem.addNew
       rsItem("orderID") = intOrderID 'same orderID
       rsItem("productID") = itemInfo(0) 'one or more
       rsItem("itemPrice") = itemInfo(1) 'one or more
       rsItem("beforeTax") = itemInfo(2) 'one or more
       rsItem("sAmt") = itemInfo(3) 'one or more
       rsItem("PST") = itemInfo(4) 'one or more
       rsItem("GST") = itemInfo(5) 'one or more
       rsItem("quantity") = itemInfo(6) 'one or more
   rsItem.Update		
		
next

I have tried to illustrate how I think it should work with the comments, essentially the outcome I am looking for is... if a user orders more than one item, I would like to insert an individual line in the table for each item while they can share the same orderID.

I am relatively new to ASP so any help is much appreciated.
 
Here is the form variable being passed

<input type="hidden" name="strOrderItem" value="<%= intStock %>,<%= intPrice %>,<%= intExtPrice %>,<%= intShipTotal %>,<%= intPSTTax %>,<%= intGetTax %>,<%= intQuant %>">

 
Ok, I have a checkout page where strOrderItem is created, the user enters data, hits submit and is taken to a confirmation page where they can verify all their info and finally on submit it hits the insert page with strOrderItem and all of the other info and is placed in the DB.

So it is kind of a lengthy process code wise.


 
The first question that comes to mind is where in your code are you assigning the value to the variable intOrderID?

A proposistion:

<input type="hidden" name="strOrderItem" value="<%=intOrderID%>,<%= intStock %>,<%= intPrice %>,<%= intExtPrice %>,<%= intShipTotal %>,<%= intPSTTax %>,<%= intGetTax %>,<%= intQuant %>">

So the code would change to:

for each item in Request.form("strOrderItem")
strOrderItem = cstr(item)
itemInfo = split(strOrderItem, ",")
rsItem.addNew
rsItem("orderID") = itemInfo(0) 'same orderID
rsItem("productID") = itemInfo(1) 'one or more
rsItem("itemPrice") = itemInfo(2) 'one or more
rsItem("beforeTax") = itemInfo(3) 'one or more
rsItem("sAmt") = itemInfo(4) 'one or more
rsItem("PST") = itemInfo(5) 'one or more
rsItem("GST") = itemInfo(6) 'one or more
rsItem("quantity") = itemInfo(7) 'one or more
rsItem.Update
next

It might be a little redundant, but it's just a suggestion.

-a6m1n0

"Don't try to reinvent the wheel." -My HS FORTRAN Professor
 
a6m1n0,

On my way home but I'll give that a whirl tonight.
 
i would suggest not doing the .addnew method

try using

conn.execute("insert into ... ")

will be better performance wise

especially since you will be loop this
 
It sounds as if you are passing data from several previous incarnations of the form all through to the last page, then attempting to insert records for each selected item into your order table.
The first thing I would check would be to make sure tat your previous page is actually populating data for all of the previous items that have been submitted. This could be done with some response.Write's in your form or even by looking at the page source.
If strOrderItem is only ever being populated with the one last item selection, then that would cause the behaviour your seeing here. Without seeing more of your form i couldn't come to a more accurate decision though.

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top