I may be wrong but this will only work if there is the same number of items in each list. This is not the case as each contentid may be assigned to any number of groupid's.

How will the code below know that the first 4 items in the groupid list belong to contentid item 1 and that the subsequent groupid items belong to contentid item 2?

Still stuck...

Cheers

Dave

At 13:20 11/18/2002 +0000, you wrote:
If you have two lists of values as I presu,e is the case, the groupID
and the contentID's, and theya re in the same order, then you simply
need to loop over one list, and then get the value from the same
position in the other list.

E.g
<cfset pos = 1>
<cfloop list="#listgroups#" index="group">
<cfset contentID = ListGetAt(contentlist,pos)>
<cfquery>
Insert into contentgroups(groupId,contentID)
Values (#group#,#contentID#)
</cfquery>
<cfset pos=pos+1>
</cfloop>



-----Original Message-----
From: Dave Phipps [mailto:[EMAIL PROTECTED]]
Sent: 18 November 2002 13:05
To: ColdFusion User group
Subject: [ cf-dev ] Looping problem - help!!!


Hi,

I have the following form which passes any number of contentid's to the
insert query.  I also have a list of groupid's which need to be
associated
with individual contentid's.  This is so that a user can assign
contentid 3
groupid's 1,3,5 and at the same time assign groupid's 2,4 to contentid
2.

The form is as follows - I tried appending the contentid to the groupid
so
that I could sort it out in the processing page but I got lost somewhere

along the way.
<form action=act_assigngroup.cfm>
<!--- This is output for each contentid from the query ---> <td><input
type="checkbox" name="contentid" value="#contentid#"
class="btn"></td>
<td width="100" class="list" valign="top"><cfloop
query="listGroups"><input
type="checkbox" name="groupid"
value="#groupid#|#list_pend_content.contentid#" class="btn" <cfif
groupname
IS "Users">CHECKED</cfif>>#groupname#<br></cfloop></td>
</form>

In my act page I have the following which is not working:

<cfloop index="i" list="#attributes.contentid#">
         <cfloop index="f" list="#attributes.groupid#" delimiters=",">
                 <cfif i eq ListGetAt(attributes.groupid, 2, "|")>
                         <cfloop index="g" list="#ListGetAt(f, 1,
"|")#">
                                 <cfquery name="assign_groups"
datasource="#request.dsn#" dbtype="ODBC">
                                         INSERT INTO content_group
(contentid, groupid)
                                         VALUES(#attributes.contentid#,
'#g#')
                                 </cfquery>
                         </cfloop>
                 </cfif>
         </cfloop>
</cfloop>

As you can see a bit of a mess.

If the code worked then I should have ended up having 5 rows in the
content_group table as follow:

contentid       |       groupid
         3       |            1
         3       |            3
         3       |            5
         2       |            2
         2       |            4

Any help with this mess that I have got myself into?

Many thanks

Dave



============================================
Phipps CF Development
Oxford, Oxfordshire.
Telephone: +44(0)7718 896696
http://www.phipps-cf.co.uk ============================================


--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED] For
human help, e-mail: [EMAIL PROTECTED]


--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]

============================================
Phipps CF Development
Oxford, Oxfordshire.
Telephone: +44(0)7718 896696
http://www.phipps-cf.co.uk
============================================


--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]

Reply via email to