|
rdouglass -> RE: Creating a number of records (1/19/2008 11:15:21)
|
quote:
<!--#include file="_fpclass/fpdbrgn1.inc"--> <!--#include file="_fpclass/fpdbrgn2.inc"--> The problem with nesting the DRW in a loop like that is in the include lines like that. You end up including them multiple times and that's a no-no. I personally don't know how to do it with the DRW and I think it's going to be a struggle using it. Using 'straight ASP' is not trivial if you're not up on ASP. However you must absolutely be able to idenify a specific row and cell of the table instead of all name fields being "Name". What I do is to basically include the record ID somehow in each row; let's make it hidden. <input type=hidden name=ID value="<%theRecordsetID%>"> Then I'd make the payment field something like this as well. <input type=text name="Payment<%theRecordsetID%>" > See what I did? Now I have payment fields named "Payment1", Payment238", Payment94", etc. based on the record ID. That make sense? Good. So now if I post the table (inside a form of course), I can now collect all the ID's of the records I want to add payments to by simply Request.Form("ID"). That will give me a comma separated list of ID's like "1,238,94". Now that I have a list of ID's, I can separate them into an array like so: myIDArray = split(Request.Form("ID"),",") I now have each ID separated into myID array. So as a rule, I always clean up a numerical array like so to remove spaces: FOR i = 0 TO ubound(myIDArray) myIDArray(i) = trim(myIDArray(i) & "") NEXT OK, so now that we have a clean array of ID's, we can generate a new INSERT line for each one like this: FOR i = 0 TO ubound(myIDArray) mySQL = "INSERT INTO Payments (ID_From_Rental_Homes, jsPmtMonth) VALUES (" & myIDArray(i) & " , '" & Request.Form("Payment" & myArray(i)) & "')" NEXT That make sense? The bold area is how I distinguish which payment with which ID. Now it's an exercise of opening the database, loop thru and execute each of the INSERT statements, and close the DB. Something like this maybe: <%
myDSN ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("/fpdb/mydatabase.mdb")
myIDArray = split(Request.Form("ID"),",")
set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN
FOR i = 0 TO ubound(myIDArray)
myIDArray(i) = trim(myIDArray(i) & "")
IF trim(Request.Form("Payment" & myArray(i)) & "") > "" Then
mySQL = "INSERT INTO Payments (ID_From_Rental_Homes, jsPmtMonth) VALUES (" & myIDArray(i) & " , '" & trim(Request.Form("Payment" & myArray(i)) & "") & "')"
conntemp.execute(mySQL)
End IF
NEXT
conntemp.close
%>
See what I'm doing? I didn't check the specific syntax but it should be close. Hope it helps
|
|
|
|