You might do better to store the information you want to go into the
child table in a structure rather than a list.  You can pull the info
out a little easier, you could also use an array.  That way you have all
your info in one place rather than 3 separate lists. 

Kevin


-----Original Message-----
From: Jeff Fongemie [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, April 09, 2002 10:47 AM
To: CF-Talk
Subject: is this even possible?? Loop using lists?

Hello cf-talk,

Is this even possible??

I have a form, that collects name, age, and gender, for a list of
  people. I get the it all as a form submission as in form.name1,
  form.age1, form.gender1, form.name2, form.age2 and so on.

  What I need to do, is create a new record in a parent table, to hold
  some other stuff for the transaction, then add each name, age and
  gender as a new record into a child table.  THe parent record and
  each child record share a customerID.

  The parent table is easy, but I'm having trouble getting a loop to
  run through and insert each name,age,gender combo as a new record in
  the child table.

  This is my attempt:

 <!--- set up list of names to loop through --->
<cfoutput>
<cfset namelist =
"#form.name1#,#form.name2#,#form.name3#,#form.name4#,#form.name5#,#form.
name6#,#form.name7#,#form.name8#,#form.name9#,#form.name10#,#form.name11
#" >

<cfset agelist =
"#form.age1#,#form.age2#,#form.age3#,#form.age4#,#form.age5#,#form.age6#
,#form.age7#,#form.age8#,#form.age9#,#form.age10#,#form.age11#" >

<cfset genderlist =
"#form.gender1#,#form.gender2#,#form.gender3#,#form.gender4#,#form.gende
r5#,#form.gender6#,#form.gender7#,#form.gender8#,#form.gender9#,#form.ge
nder10#,#form.gender11#" >

<!--- set up the number of items in the list so we know when to stop
--->
<cfset length=listLen(nameList)>

</cfoutput>


THEN, I INSERT to the parent table to make a new record and get a
customerID.

Now the hard part:  I'm having trouble getting a loop to use all three
lists. Is the following even close??


        <cfquery name="addmembers" datasource="pfestregistration"
dbtype="ODBC">
<cfloop from="1" to="#length#" list="#namelist#">
INSERT INTO Customers_members

(customerid,
name,
age,
gender,
        address, 
        address2, 
        city, 
        state, 
        zip, 
        telephone, 
        email,
        emergencycontact,
        emergencynumber)
Values 
('#customerid#', 

'#namelist#',
'#agelist#',
'#genderlist#',

'#form.address2#', 
'#form.city#', 
'#form.state#', 
'#form.zip#', 
'#form.telephone#',
'#form.email#',
'#form.emergencycontact#',
'#form.contactnumber#'); 

</cfloop>
</cfquery>
  


Best regards,
 Jeff Fongemie                          mailto:[EMAIL PROTECTED]
------------------------ 


______________________________________________________________________
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to