title: mysql query based on checkboxes and input boxes
body: <p>So I'm trying to create a MySQL query based on input by the user.  I have a ton of checkboxes (around 50), so I don't want to do them individually.  Here's just a few of my checkboxes:</p>
  
  <pre><code>&lt;input type="checkbox" name="check_list[]" value="ki67" /&gt;  ki67&lt;br&gt;&lt;br&gt;
  &lt;input type="checkbox" name="check_list[]" value="myc" /&gt;  myc&lt;br&gt;&lt;br&gt;
  &lt;input type="checkbox" name="check_list[]" value="mta1" /&gt;  mta1&lt;br&gt;&lt;br&gt;
  &lt;input type="checkbox" name="check_list[]" value="mvd/cd34" /&gt;  mvd/cd34&lt;br&gt;&lt;br&gt;
  </code></pre>
  
  <p>I then run them through PHP to tell the user what has been checked:</p>
  
  <pre><code>if(!empty($_POST['check_list'])) {
      foreach($_POST['check_list'] as $check) {
          echo $check . "&lt;br&gt;";
      }
  }
  </code></pre>
  
  <p>Now I would like to run them through a MySQL process to display how many rows have been selected.  Here's my code for that part:</p>
  
  <pre><code>&lt;?php 
  //perform database query
  $query = "SELECT COUNT(*) ";
  $query .= "FROM testdata ";
  
  if(!empty($_POST['check_list'])) {
      foreach($_POST['check_list'] as $check) {
          $query .= "WHERE rd_$check = 1";
      }
  }
  </code></pre>
  
  <p>Then later:</p>
  
  <pre><code>$result = mysqli_query($link, $query);
  if (!$result) {
      die("Database query failed.");
  }
  </code></pre>
  
  <p>The problem comes when I try to check multiple boxes.  I don't know how to concatenate more onto <code>$query</code>.  The command would have to look something like:</p>
  
  <pre><code>SELECT COUNT(*) FROM testdata WHERE rd_ki67 = 1 AND rd_myc = 1 AND ...;
  </code></pre>
  
  <p>Does anyone know how to do this?</p>