Jump to content

FIND_IN_SET


steveangelis

Recommended Posts

I have a headache of a query I am trying to write but I cannot seem to make it do what I want it to do:

 

select userid,username,membergroupids,lastvisit from user WHERE FIND_IN_SET('146,', membergroupids) AND FIND_IN_SET('$id1', membergroupids)  or FIND_IN_SET('$id2', membergroupids) order by username asc

 

This query is doing exactly what it shows but not what I want.  What I want it to do is get all the data with 146 in it that ALSO contain either $id1 or $id2 but what it is getting is everyone that has 146 and in $id1 but also, everyone that is just in $id2.  Does anyone know how to fix it?

 

This is what it should do:

everyone = 146+$id1

everyone = 146+$id2

 

This is what it is doing:

everyone = 146+$id1

everyone = $id2

Link to comment
https://forums.phpfreaks.com/topic/170536-find_in_set/
Share on other sites

Just throwing this out there (never used FIS before), but it might be a parenthesis issue? Try:

select userid,username,membergroupids,lastvisit from user WHERE FIND_IN_SET('146,', membergroupids) AND (FIND_IN_SET('$id1', membergroupids)  or FIND_IN_SET('$id2', membergroupids)) order by username asc

 

Link to comment
https://forums.phpfreaks.com/topic/170536-find_in_set/#findComment-899552
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.