Answer the question
In order to leave comments, you need to log in
How to do "OR" in bitmask filtering?
Good time, I have InstantCMS.
Filters - checkboxes.
Example:
- Mom - checked
- Dad
- Grandmother - checked
- Grandfather
- Grandson - checked
Save, get in the DB field:
10101
Now selected by the LIKE condition.
If, for example, Grandfather and Grandson are marked, then the following mask will be formed in the query in the database:
LIKE '___11%' - and the query will return nothing. How to make filtering work in logic "or"?
Those. "Grandson" is true, so return the result. Through LIKE, it seems that this cannot be implemented. How to proceed here?
Answer the question
In order to leave comments, you need to log in
If you have presented your checkboxes as bits, then continue to work with them.
Yours 10101
is 21.
Grandfather and grandson are 3.
Compare by mask 21 & 3 = 1
. This is greater than 0, so it suits us.
We check on the folder - this is 8. 21 & 8 = 0
. And this is 0, which means by.
Another thing is that you may have to tinker with indexes.
Here is a similar example:
sqlfiddle.com/#!9/bd5f72/9 The
only caveat is that there can only be 64 values in a bitmask :)
Otherwise, an auxiliary table is needed, filtering by row is not really an option at all.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question