4 Replies Latest reply on Feb 15, 2007 6:07 AM by DettCom

    Please Help - looping through groups

    DettCom
      Hello all,

      I am having quite a time trying to loop through a series of group id's returned from a user query and getting correct results.

      1. I have a form where you can select multiple groups to send to (form.group_id).
      2. I create a cfloop to go through all of the users returned and then a second to loop through the groups selected:

      <cfloop query="get_users">
      <cfloop list="#get_users.group_id#" index="x" delimiters=",">
      <cfif #form.group_id# CONTAINS #x#>
      Go ahead and send out a message
      </cfif>
      </cfloop>
      </cfloop>

      The problem is that if I select the following groups: 3, 6, 1

      It will return 10, 11, 12 , 13, etc. because it has a one in it.

      I have tried <cfif #REFind(form.group_id, x)#> and it still would not give me correct results. Ideally, I would like to do this via an SQL query but I did not know how to do it.

      Example:
      <CFQUERY Name = "get_users" Datasource = #application.dsn#>
      SELECT *
      FROM SUBSCRIPTION
      WHERE group_id CONTAINS #form.group_id#
      </CFQUERY>

      Any ideas????

      Thanks!

      Code attached