Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Comparing 2 arrays

Posted on 2001-06-21
5
Medium Priority
?
150 Views
Last Modified: 2013-12-24
Okay. I have a table with Groups assigned to a user and a table with Groups assigned to an event.

I am storing the info from each table in a one dimensional array. (This I have working).

One array has Group ID's assigned to a user, the other has all Group ID's assigned to an event.  

I want to compare the 2 arrays and see if the Group ID's associated with the user are in the Group ID's from the event.

If they are set a flag on the ones that are the same.

The purpose is to either show or hide info from the user on the display page based on whether they are in a certain group or not.

Can anyone help? Thanks in advance.
0
Comment
Question by:Zoo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:CF_Spike
ID: 6214317
How exactly are the arrays organised?

what does the array index represent and what does the array data represent?

i.e. Is the groupID the array index number or is it the data for that index in the array?

Spike
0
 

Author Comment

by:Zoo
ID: 6214389
the arrays are filled with data (numbers to be exact), as in:

Array 1 - 1, 23, 56, 89 , 78

Array 2 - 1, 2, 3, 56, 78, 98

The numbers are unique ID's of groups.

I want to compare these and where they are the same print to the screen, if they are not the same do not print.

So in the case above print out the events that correspond to numbers 1, 56, and 78.


Here is my code:

Array 1:

<CFQUERY DATASOURCE="#request.MainDSN#" NAME="qryGetGroups">
    SELECT  group_id
    FROM GroupTracking
    WHERE Event_ID = #attributes.Event_ID#
</CFQUERY>

<CFSET arrGetGroups = ArrayNew(1)>
<CFSET numCount = 1>
<CFOUTPUT QUERY="qryGetGroups">
<CFSET Variables.arrGetGroups[#Variables.numCount#] = #group_id#>
<CFSET Variables.numCount = Variables.numCount + 1>
</CFOUTPUT>


Array 2:

<CFQUERY DATASOURCE="#request.MainDSN#" NAME="qryUserGroups">
SELECT      gm.group_id, gm.user_id, u.user_lastname, g.group_name
FROM GROUPMEMBERSHIP gm, USERS u, GROUPS g
WHERE u.user_id = #session.numUserID#
AND gm.user_id = u.user_id
AND gm.group_id = g.group_id
</CFQUERY>


<CFSET arrGetUsersGroups = ArrayNew(1)>
<CFSET numCount = 1>
<CFOUTPUT QUERY="qryUserGroups">
<CFSET Variables.arrGetUsersGroups[#Variables.numCount#] = #group_id#>
<CFSET Variables.numCount = Variables.numCount + 1>
</CFOUTPUT>
0
 
LVL 4

Expert Comment

by:CF_Spike
ID: 6214446
This should work:

<CFSET listUsersGroups = ArrayToList(variables.arrGetUsersGroups)>
<CFOUTPUT>
<CFLOOP From="1" TO="#ArrayLen(Variables.arrGetGroups)#" Index="i">
<CFSET
<CFIF ListFind(listUsersGroups,Variables.arrGetGroups[i]))>
#Variables.arrGetGroups[i]#
</CFIF>
</CFLOOP>
</CFOUTPUT>

You would probably want to do something other than just print out the value, but hopefully you get the idea.

Spike
0
 
LVL 4

Accepted Solution

by:
CF_Spike earned 400 total points
ID: 6214451
Better remove that unclosed cfset just after the opening cfloop tag before you try to run the code.
0
 

Author Comment

by:Zoo
ID: 6214469
That worked great. Thanks!!
0

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

596 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question