Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8130695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:49:08+00:00 2026-06-06T08:49:08+00:00

Imagine it like this. There is a field in my database called flags in

  • 0

Imagine it like this. There is a field in my database called flags in which are added or removed data like this:

UPDATE people SET flags=flags|16 WHERE ....
UPDATE people SET flags=flags|128 WHERE ....
UPDATE people SET flags=flags&~16 WHERE ....
UPDATE people SET flags=flags&~128 WHERE ....

For instance this field can have value like 65536 or more or less. My question is – How to get specific flag from this field using PHP code? I mean something like this:

SELECT * FROM people WHERE flags=16;

But the result will return all people with not just number 16 in field but it will return people with flag 65536, people with 16 but not people with 2 or 1. Which SELECT query should I use here in my php code or maybe some specific PHP integrated functions? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:49:10+00:00Added an answer on June 6, 2026 at 8:49 am

    Assuming flags is a bitfield and you want to select rows where bit #4 (10000) is set

    SELECT * FROM people WHERE flags & 16;
    

    This is not ideal though as you’re losing out on all that referential goodness that DBs are good for.

    What you should have is two new tables; flags and people_flags. The former contains all the flags (id and name columns should be sufficient). The latter contains flag_id and people_id columns, creating a many-to-many relationship (see junction table).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have a recursive algebraic data type like this (Haskell syntax): data Expr
Imagine a database table that looks like this: create table [dbo].[user] ( id int
I have a field that contains data like below: 124.97#54.03#5#16 its number which separated
Imagine a class like this: public class MyEntity : Entity { public virtual States
Imagine a simple case like this: class Book has_many :chapters end Let's say in
Imagine I have a document like this: post = {title: a, comments: [{hour: 08:00,
Imagine I have a template function like this: template<typename Iterator> void myfunc(Iterator a, typename
I imagine to use XML serialization like this: class Foo { public Foo (string
Imagine that I want to create an array from another array like this: $array
I know this sucks. Date stuff sucks hard. But: Imagine a date format like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.