Uutiset:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu
Advertisement:

mysql: find one of an array in an array

Aloittaja JPDeni, toukokuu 21, 2008, 08:21:17 IP

« edellinen - seuraava »

JPDeni

I'm trying to figure out how to find one of the elements in an array in a field that is an array. Specifically, I want to be able to define several group numbers and have it look for any one of those numbers in the "additionalGroups" field in the smf_member table. I have


$groups_array = array(1,2,3);


What is the "WHERE" syntax to find whether any one of those numbers is included in any of the numbers in the addtionalGroups field?

karlbenson

#1
FIND_IN_SET
FIND_IN_SET(". $group . ", mem.additionalGroups))

OR

IN
ID_POST_GROUP IN ($groups)
(where groups is 1,2,3,4,5)

To check all the groups smf uses a where clause like

WHERE (mem.ID_GROUP IN (" . implode(', ', $groups) . ") OR mem.ID_POST_GROUP IN (" . implode(', ', $groups) . ") OR FIND_IN_SET(" . implode(", mem.additionalGroups) OR FIND_IN_SET(", $groups) . ", mem.additionalGroups))

JPDeni


Advertisement: