title: Smartest way to make php and mysql query to handle "multiple choice" in WHERE part
body: <p>I have a table which should handle user access to customer in specific countries. A user can have access to only one country, or have access to all countries or everything in between.</p>
  
  <p>Something like this: (1 = access, 0 no access)</p>
  
  <p><em>The rest is multiple countries like CH, UK and more. But maybe with only one hit pr. country, so it was decided to be pooled together at some point. Not smart, but that it what it is.</em></p>
  
  <pre><code>|----|----|----|----|----------|
  | DK | DE | NO | SE | The rest |
  |----|----|----|----|----------|
  | 0  | 0  | 0  | 0  |    0     |
  | 1  | 0  | 0  | 0  |    0     |
  | 0  | 1  | 0  | 0  |    0     |
  | 0  | 0  | 1  | 0  |    0     |
  | 0  | 0  | 0  | 1  |    0     |
  | 0  | 0  | 0  | 0  |    1     |
  | 1  | 1  | 0  | 0  |    0     |
  | 1  | 0  | 1  | 0  |    0     |
  |        ...                   |
  |        ...                   |
  |        ...                   |
  | 1  | 1  | 1  | 1  |    1     |
  |----|----|----|----|----------|
  </code></pre>
  
  <p>Is there a smart way to easily type the query in php, so I don't have to make many if-sentences?
  It doable with IF's, but very cumbersome write, and even more if changes needs to be made.</p>
  
  <p>So I'm thinking there must be a better way to do this.</p>
  
  <p>EDIT
  hasAccess() return 1 or 0, depending on access or not. The following is that I want to optimize if possible.</p>
  
  <pre><code>        if (hasAccess('dk_kunde')) { //adgang til dk kunde
          if (hasAccess('no_kunde')) { //adgang til no
              if (hasAccess('sv_kunde')) { //adgang til se
                  if (hasAccess('de_kunde')) { //adgang til de
                      $WHERELAND = "WHERE land = 'dk' OR land = 'n' OR land = 's' OR land = 'd' ";
                  } else { //ikke adgang til de
                      $WHERELAND = "WHERE land = 'dk' OR land = 'n' OR land = 's' ";
                  }
              } else {
                  $WHERELAND = "WHERE land = 'dk' OR land = 'n' ";                    
              }
          } else { //ikke adgang til no
             if (hasAccess('sv_kunde')) {
                  if (hasAccess('de_kunde')) { //adgang til de
                      $WHERELAND = "WHERE land = 'dk' OR land = 's' OR land = 'd' ";
                  } else { //ikke adgang til de
                      $WHERELAND = "WHERE land = 'dk' OR land = 's' ";
                  }
              } else { // ikke adgang til se
                  if (hasAccess('de_kunde')) { //adgang til de
                      $WHERELAND = "WHERE land = 'dk' OR land = 'd' ";
                  } else { //ikke adgang til de
                      $WHERELAND = "WHERE land = 'dk' "; 
                  }
              }
          }
      } else { //ikke adgang til dk
          if (hasAccess('no_kunde')) { //adgang til no
              if (hasAccess('sv_kunde')) { //adgang til se
                  if (hasAccess('de_kunde')) { //adgang til de
                      $WHERELAND = "WHERE land = 'n' OR land = 's' OR land = 'd' ";
                  } else { //ikke adgang til de
                      $WHERELAND = "WHERE land = 'n' OR land = 's' ";
                  }
              } else {
                  if (hasAccess('de_kunde')) { //adgang til de
                      $WHERELAND = "WHERE land = 'n' OR land = 'd' ";
                  } else { //ikke adgang til de
                      $WHERELAND = "WHERE land = 'n' ";
                  }
              }
          } else { //ikke adgang til dk og no
              if (hasAccess('sv_kunde')) { //adgang til sv
                  if (hasAccess('de_kunde')) { //adgang til de
                      $WHERELAND = "WHERE land = 's' OR land = 'd' ";
                  } else { //ikke adgang til de
                      $WHERELAND = "WHERE land = 's' ";
                  }
              } else {
                  if (hasAccess('de_kunde')) { //adgang til de
                      $WHERELAND = "WHERE land = 'd' ";
                  } 
              }
          }
      }
  </code></pre>