A
A
Absolute1382020-06-15 13:18:36
MySQL
Absolute138, 2020-06-15 13:18:36

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

2 answer(s)
F
freeExec, 2020-06-15
@Absolute138

If you have presented your checkboxes as bits, then continue to work with them.
Yours 10101is 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.

A
Anton Anton, 2020-06-15
@Fragster

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 question

Ask a Question

731 491 924 answers to any question