Simple Machines Community Forum

General Community => Scripting Help => Aiheen aloitti: JPDeni - toukokuu 21, 2008, 08:21:17 IP

Otsikko: mysql: find one of an array in an array
Kirjoitti: JPDeni - toukokuu 21, 2008, 08:21:17 IP
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?
Otsikko: Re: mysql: find one of an array in an array
Kirjoitti: karlbenson - toukokuu 21, 2008, 08:35:58 IP
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))
Otsikko: Re: mysql: find one of an array in an array
Kirjoitti: JPDeni - toukokuu 21, 2008, 08:45:58 IP
Thanks!