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 1027337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:13:32+00:00 2026-05-16T12:13:32+00:00

The problem I have a list of tasks with which a user is greeted

  • 0

The problem

I have a list of tasks with which a user is greeted with upon login. I want to be able to
filter tasks according to assignment. The relevant fields on the table are:

**tasks table**
task_id   | (FK int) user  | (FK int) team
            (assigned to)    (assigned to)

And users belong to one team. On the front end I have checkboxes:

[ ] Mine     [ ] My Team's   [ ] Others    (Filter)

The conditions are mutually exclusive. For example, if I only check "My Team’s", it’s implied that
I want to see all tasks assigned to my team but not me. If I check "Mine", I only want to see tasks assigned to me.

I can use any combination of the checkboxes to filter my results.

The (ugly) solution:

Convert flags as binary number to an int (little endian) and use switch:

$num = bindec("{$flag1}{$flag2}{$flag3}");

switch ($num) {
    // [ ] Mine   [ ] My Team's   [X] Others
    case 1:
        $filter = array('team <>' => $teamId);
        break;
    // [ ] Mine   [X] My Team's   [X] Others
    case 3:
        $filter = array('user <>' => $userId);
        break;

    /* a few more */

    // [X] Mine   [X] My Team's   [X] Others
    default:
        $filter = array();
        break;
}

The generated $filter array is passed on to a query builder.
It works. But I feel this is really ugly. Is there a better way?

  • 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-05-16T12:13:33+00:00Added an answer on May 16, 2026 at 12:13 pm

    Well, personally I don’t think that’s too ugly…

    Why not just create two filter arrays (one for and, the other for or)

    $andFilter = array();
    $orFilter = array();
    if ($flag1) {
        $orFilter['user = '] = $userId;
    } else {
        $andFilter['user <> '] = $userId;
    }
    if ($flag2) {
        $orFilter['team = '] = $teamId;
    } else {
        $andfilter['team <> '] = $teamId;
    }
    if ($flag3) {
        $orFilter['1 = '] = 1;
    }
    

    Then, join the queries as ($orFilter) AND ($andFilter) where each element of the filter is separated by the respective boolean operator (OR for $orFilter, AND for $andFilter)…

    It should satisfy all your needs, and be relatively future proof (as you can add flags as you see fit)…

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

Sidebar

Related Questions

I have a Foo object, and a std::list holding instances of it. My problem
Problem: I have an address field from an Access database which has been converted
Problem I have timestamped data, which I need to search based on the timestamp
I have some problems on a site with the concurrent access to a list.
I'm trying to build my first generic list and have run into some problems.
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem: We have a web app that calls some web services asynchronously (from the
Problem: I have to support users who need to edit web pages. Some of
I have the following problem: I have an HTML textbox ( <input type=text> )
I have problem in some JavaScript that I am writing where the Switch statement

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.