N
Nick
Loop to create an array from a dynamic form.
I'm having trouble with an application, and I'll try to explain it as
clearly as possible:
1. I have a form with two fields, say Apples and Oranges. The user
selects from a drop down menu, between 1-10 of each and clicks submit.
The resulting page will display a NEW form, with rows and a list of
fields for the amount of each items selected.
Example. If I selected 3 apples and 5 oranges, the resulting page
would show 3 rows of text fields for apples and 5 rows of text fields
for oranges.
The form fields would be (after each semicolon, the first word is the
form element name (Apple1, Apple2)):
Apple1: net price | gross price | date | time
Apple2: net price | gross price | date | time
Apple3: net price | gross price | date | time
Orange1: net price | gross price | date | time
Orange2: net price | gross price | date | time
Orange3: net price | gross price | date | time
Orange4: net price | gross price | date | time
Orange5: net price | gross price | date | time
I want to insert each one of these records into the database, each
record being a net, gross price, date and time for apple 1-X and
orange 1-X. The apples will go into the apple table and the oranges
will go into the oranges table.
I'm used to looping like this:
for each item in request.form
if left(item, 6) = "orange" then
orange = orange & request.form(item) & ","
end if
next
After that, I'll create a loop that inserts each record into the
database separately, something of this nature:
for each item in orange
set rsOrange= server.createobject("adodb.recordset")
strSql = "select * from oranges"
rsOrange.open strSql, Connstr, 1, 3
rsOrange.Addnew
rsOrange("net") = request.form("net")
rsOrange("gross") = request.form("gross")
rsOrange("date") = request.form("date")
rsOrange("time") = request.form("time")
rsOrange.Update
rsOrange.close
next
But since this is a multi dimensional array (gross, net, date, time
will need to be inserted correspondingly), you can see my dilemma. I
understand how they work when hard coded, but not to dynamically
create and populate them, then use in an insert statement. Sorry if
this is elementary, but any help would really be appreciated.
Thanks!
I'm having trouble with an application, and I'll try to explain it as
clearly as possible:
1. I have a form with two fields, say Apples and Oranges. The user
selects from a drop down menu, between 1-10 of each and clicks submit.
The resulting page will display a NEW form, with rows and a list of
fields for the amount of each items selected.
Example. If I selected 3 apples and 5 oranges, the resulting page
would show 3 rows of text fields for apples and 5 rows of text fields
for oranges.
The form fields would be (after each semicolon, the first word is the
form element name (Apple1, Apple2)):
Apple1: net price | gross price | date | time
Apple2: net price | gross price | date | time
Apple3: net price | gross price | date | time
Orange1: net price | gross price | date | time
Orange2: net price | gross price | date | time
Orange3: net price | gross price | date | time
Orange4: net price | gross price | date | time
Orange5: net price | gross price | date | time
I want to insert each one of these records into the database, each
record being a net, gross price, date and time for apple 1-X and
orange 1-X. The apples will go into the apple table and the oranges
will go into the oranges table.
I'm used to looping like this:
for each item in request.form
if left(item, 6) = "orange" then
orange = orange & request.form(item) & ","
end if
next
After that, I'll create a loop that inserts each record into the
database separately, something of this nature:
for each item in orange
set rsOrange= server.createobject("adodb.recordset")
strSql = "select * from oranges"
rsOrange.open strSql, Connstr, 1, 3
rsOrange.Addnew
rsOrange("net") = request.form("net")
rsOrange("gross") = request.form("gross")
rsOrange("date") = request.form("date")
rsOrange("time") = request.form("time")
rsOrange.Update
rsOrange.close
next
But since this is a multi dimensional array (gross, net, date, time
will need to be inserted correspondingly), you can see my dilemma. I
understand how they work when hard coded, but not to dynamically
create and populate them, then use in an insert statement. Sorry if
this is elementary, but any help would really be appreciated.
Thanks!