Jump to content


Photo

Comparing Two Values (Arrays)


  • Please log in to reply
1 reply to this topic

#1 PattyB

PattyB
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 30 October 2006 - 11:01 PM

I am trying to compare the values of two things.

The first set of values comes from a multi-select and outputs like this:  item1,item2,item3,  and etc. for however many options I choose.  I am not sure if this needs to be converted into an array or if it can stay like is?

The second set of values comes from a mysql table.  Say this table contains two fields: email and groups.

What I want to do is compare the first output (item1,etc) to the value of what is in the field groups and have an if statement if there is a match.

For example:  I have a list of users in a table along with their email and groups they belong to.  The user will select the groups they want from a multi-select.  I want to compare the groups selected to the groups each user belongs too and if there is a match to do something.

Im guessing array_intersect can play a role in this but I have been playing for a while and cant get anything to work. 

Any help would be very grateful.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 31 October 2006 - 01:47 AM

I'd use the query to select records only form the groups that the use selected

SELECT * FROM users WHERE group IN ('item1', 'item2'. 'item3')
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users