• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Please Help - looping through groups

Guest
Feb 14, 2007 Feb 14, 2007

Copy link to clipboard

Copied

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
TOPICS
Advanced techniques

Views

341

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 14, 2007 Feb 14, 2007

Copy link to clipboard

Copied

How about using ListFind instead of Contains...
Deal with Exact comparrisons and you wont have that issue.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 14, 2007 Feb 14, 2007

Copy link to clipboard

Copied

I was looking at that before and it did not work. Of course now it does. Thank you so much.

Do you know of any way I could do this in the SQL query??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 14, 2007 Feb 14, 2007

Copy link to clipboard

Copied

Instead of Contains, use IN

where group_id IN (#form.group_id#)

-- How about marking me as giving the answer, and not yourself...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 15, 2007 Feb 15, 2007

Copy link to clipboard

Copied

LATEST
Thanks for all your help!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation