title: Changing SQL "Where" clause based on form input
body: <p>Trying to figure out a simpler method besides this huge section of code to dynamically create this SQL statement</p>
  
  <p>On the form I have checkboxes engine1 - engine6 of which someone could select all or none of (selecting none currently = effectively the same as selecting all which is how I want it)</p>
  
  <p>the below code works and generates the SQL statement correctly just wondering if there is a better way to do it?</p>
  
  <p>First section of code determines what the first checkbox is and the second set of code adds the remaining ones based on check status and includes the needed "OR" to the statement.</p>
  
  <pre><code>   $SQLselect  = "SELECT * FROM enginedataview ";
      if (!empty($_POST["engine1"])){
          $SQLselect = $SQLselect ."WHERE engine_id = 1";
          $starteng=1;
      }
      elseif (!empty($_POST["engine2"])){
          $SQLselect = $SQLselect ."WHERE engine_id = 2";
          $starteng=2;
      }   
      elseif (!empty($_POST["engine3"])){
          $SQLselect = $SQLselect ."WHERE engine_id = 3";
          $starteng=3;
  
      }   
      elseif (!empty($_POST["engine4"])){
          $SQLselect = $SQLselect ."WHERE engine_id = 4";
          $starteng=4;
  
      }
      elseif (!empty($_POST["engine5"])){
          $SQLselect = $SQLselect ."WHERE engine_id = 5";
          $starteng=5;
  
      }       
      elseif (!empty($_POST["engine6"])){
          $SQLselect = $SQLselect ."WHERE engine_id = 6";
          $starteng=6;
  
      }       
      switch($starteng){
          case "1":       
              if (!empty($_POST["engine2"])){$SQLselect = $SQLselect ." OR engine_id = 2";}
              if (!empty($_POST["engine3"])){$SQLselect = $SQLselect ." OR engine_id = 3";}
              if (!empty($_POST["engine4"])){$SQLselect = $SQLselect ." OR engine_id = 4";}
              if (!empty($_POST["engine5"])){$SQLselect = $SQLselect ." OR engine_id = 5";}
              if (!empty($_POST["engine6"])){$SQLselect = $SQLselect ." OR engine_id = 6";}
              break;
          case "2":
              if (!empty($_POST["engine3"])){$SQLselect = $SQLselect ." OR engine_id = 3";}
              if (!empty($_POST["engine4"])){$SQLselect = $SQLselect ." OR engine_id = 4";}
              if (!empty($_POST["engine5"])){$SQLselect = $SQLselect ." OR engine_id = 5";}
              if (!empty($_POST["engine6"])){$SQLselect = $SQLselect ." OR engine_id = 6";}   
              break;
          case "3":
              if (!empty($_POST["engine4"])){$SQLselect = $SQLselect ." OR engine_id = 4";}
              if (!empty($_POST["engine5"])){$SQLselect = $SQLselect ." OR engine_id = 5";}
              if (!empty($_POST["engine6"])){$SQLselect = $SQLselect ." OR engine_id = 6";}   
              break;
          case "4":
              if (!empty($_POST["engine5"])){$SQLselect = $SQLselect ." OR engine_id = 5";}
              if (!empty($_POST["engine6"])){$SQLselect = $SQLselect ." OR engine_id = 6";}
              break;
          Case "5":
              if (!empty($_POST["engine6"])){$SQLselect = $SQLselect ." OR engine_id = 6";}   
              break;
      }   
  </code></pre>