SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Solved: What is this programming concept called? Requires explanation.

    UPDATE: Nevermind. My memory just kicked in and I realized that I'm describing bitwise operations.



    Let's say I have a search form with the following options:
    Code:
    category
    ountry
    state
    A user could perform a search using none, some, or all of the above options.

    I recall coming across a coding method that determined it's SQL search string, not based on multiple IF statements, but by using a SUM of the search values. It's a little difficult to explain, so here's what I mean:
    Code:
    no search values specified:
      value: 0
    
    category specified:
      value: 1
    
    country specified:
      value: 2
    
    state specified:
      value: 4
    
    category and country specified:
      value: 3 (1 + 2)
    
    category, country, and state specified:
      value: 7 (1 + 2 + 4)
    
    country and state specified:
      value: 6 (2 + 4)
    As you see above every search scenario will (should?) only have one possible value. Then you could use a switch statement to choose the proper SQL string.
    PHP Code:
    switch ($value) {
        case 
    0:
            
    // run sql query 0

        
    case 1:
            
    // run sql query 1

        
    case 2:
            
    // run sql query 2

        
    case 7:
            
    // run sql query 7
            // etc
            // etc
            // etc

    My question is, what is this programming concept called? I want to do further research on it but don't know what to search for.

    Please share your opinions on this concept as well. Good, bad, stupid?

  2. #2
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    binary.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •