PDA

View Full Version : multi update | adding/splitting variables


Keltoi
08-21-2003, 03:29 PM
I need to write an update page which will update multiple records in a
table.
In this case I need to update the quantity of any one product in a list.

So far I have the form with the variables "id" and "qty" for each product.
I just need to isolate these for use in an update command.

Here is what I have so far, this is wrong, but can anyone tell me what is right?

myStringID=Request.form("id")
myArrayID=split(myStringID,",")
myStringQty=Request.form("qty")
myArrayQty=split(myStringQty,",")

for i=0 to ubound(myArrayID)
for q=0 to ubound(myArrayQty)
'as a test
Response.Write(myArrayID(i) & " = " & myArrayQty(q) & "<br>"
Next
Next

Any help, much appreciated

IdentityCrisis
08-21-2003, 03:39 PM
Can you give us an example of what the error message is.. that would help us know what to look for (at least, it would help me for sure.)

Keltoi
08-21-2003, 03:47 PM
Not getting an error as such just the wrong combination of variables.
in the above example I pass these variables from the update form:

ID = 38, Qty = 1
ID = 39, Qty = 2

And it prints this:

38 = 1
38 = 2
39 = 1
39 = 2

What I need is something like:

38 = 1
39 = 2

Does that make sense?

IdentityCrisis
08-21-2003, 03:51 PM
Yup... it makes perfect sense... you have one too many loops...

here's what would work: (Changes are in bold)
myStringID=Request.form("id")
myArrayID=split(myStringID,",")
myStringQty=Request.form("qty")
myArrayQty=split(myStringQty,",")

for i=0 to ubound(myArrayID)
'as a test - NOTE: REMOVED SECOND FOR LOOP
Response.Write(myArrayID(i) & " = " & myArrayQty(i) & "<br>"
Next
As long as your arrays are in the same order (IE, qty is in the same order as ProductID) this will be fine, you can use the same loop reference (your variable "i") for both arrays.

Hope that helps...

Keltoi
08-21-2003, 03:57 PM
Sorted, thanks IdentityCrisis,

I thought I was doing right, but just got carried away :rolleyes:

Learn a little every day...


Thanks loads.

IdentityCrisis
08-21-2003, 04:01 PM
You're very welcome... it's what this forum's all about! :thumbsup: