title: Multiple Select MySqL Query Using IN Operator?
body: <p>I have been trying to make this webpage work for a while but keep getting problems. In this webpage, I have a series of selection boxes (some are independent and some are depended on another) to make selections and then apply filter to make a query. It is still in test-mode and working fine for single selections. But I have still not managed to make it work for multiple selections in same selection boxes. For example; When I select Europe and North America in Region Box and apply the filter it gives no result when I'd expect it to give me the results of the companies which are in Europe OR North America. You can find the test webpage here: <a href="http://gorevler.awardspace.biz/realdeal04.html" rel="nofollow">http://gorevler.awardspace.biz/realdeal04.html</a>  </p>
  
  <p>I have been trying to use "implode" and IN operator in .PHP file but don't know where I am doing wrong at. I'd appreciate it if you could you please show me the right way of doing it. You can find the coding below:</p>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>&lt;?php
  
  error_reporting(E_ALL); ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ERROR |     MYSQLI_REPORT_STRICT);
  
  $DB_HOST = "*****"; $DB_USER = "*****"; $DB_PASS = "*****"; $DB_NAME =   "*******";
  
  $con = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME); if($con-&gt;connect_errno &gt; 0) {       die('Connection failed [' . $con-&gt;connect_error . ']'); }
  
  
  $bolge= "'" . implode("', '", $_POST['filtre_region']) . "'" ;
  $bolge1= mysqli_real_escape_string($con,$bolge);
  
  $ulke= "'" . implode("', '", $_POST['filtre_country']) . "'";
  $ulke1= mysqli_real_escape_string($con,$ulke);
  
  $sektor= "'" . implode("', '", $_POST['filtre_sector']) . "'";
  $sektor1= mysqli_real_escape_string($con,$sektor);
  
  $altsektor= "'" . implode("', '", $_POST['filtre_subsector']) . "'";
  $altsektor1= mysqli_real_escape_string($con,$altsektor);;
  
  $urun= "'" . implode("', '", $_POST['filtre_product']) . "'"; 
  $urun1= mysqli_real_escape_string($con,$urun);
  
  $sql = mysqli_query("SELECT * FROM gorevler WHERE region IN ('$bolge1') AND country IN ('$ulke1')     AND sector IN ('$sektor1') AND sub_sector IN ('$altsektor1') AND product IN ('$urun1')");
  
  echo "&lt;table border='0'&gt;
  &lt;tr&gt;
  &lt;th&gt;No&lt;/th&gt;
  &lt;th&gt;Company&lt;/th&gt;
  &lt;th&gt;Region&lt;/th&gt;
  &lt;th&gt;Country&lt;/th&gt;
  &lt;th&gt;Sector&lt;/th&gt;
  &lt;th&gt;Sub Sector&lt;/th&gt;
  &lt;th&gt;Product&lt;/th&gt;
  &lt;th&gt;Website&lt;/th&gt;
  &lt;/tr&gt;";
  
  while ($row = mysqli_fetch_array($sql)){
  
  
  echo "&lt;td&gt;" .  ''.$row['no'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . ''.$row['company'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . ''.$row['region'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . ''.$row['country'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . ''.$row['sector'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . ''.$row['sub_sector'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . ''.$row['product'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . ''.$row['website'] . "&lt;/td&gt;";
  echo "&lt;/tr&gt;";
  }
  echo "&lt;/table&gt;";
  
  ?&gt;
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;form id="filtersForm" action="search_company.php" method="post" target="_blank"&gt;
  
  &lt;fieldset id="filtersPane"&gt;
  
  &lt;div class="part03_line01" id="part03_line01"&gt;
  
    &lt;div class="filter_bolge" id="filtre_bolge"&gt;&lt;p&gt;Region:&lt;/p&gt;
     &lt;select id="filter_region" name="filtre_region[]" class="select_bolge" title="Select a region" multiple="multiple" size="5"&gt;
       &lt;/select&gt;    
        &lt;/div&gt;
  
    &lt;div class="filter_ulke" id="filtre_ulke"&gt;&lt;p&gt;Country:&lt;/p&gt;
     &lt;select id="filter_country" name="filtre_country[]" class="select_ulke" title="Select a   country" multiple="multiple" size="5"&gt;
       &lt;/select&gt;    
  
    &lt;/div&gt;   
  
    &lt;div class="filter_sektor" id="filtre_sektor"&gt;&lt;p&gt;Sector:&lt;/p&gt;
     &lt;select id="filter_sector" name="filtre_sector[]" class="select_sektor" title="Select a  sector" multiple="multiple" size="5"&gt;
       &lt;/select&gt;    
  
  &lt;/div&gt; 
  
  &lt;div class="filter_altsektor" id="filtre_altsektor"&gt;&lt;p&gt;Sub Sector:&lt;/p&gt;
    &lt;select id="filter_subsector" name="filtre_subsector[]" disabled="disabled"  class="select_altsektor" title="Select a sub-sector" multiple="multiple" size="5"&gt;
  &lt;option value="" data-filter-type="" selected="selected"&gt;
  -- Make a Choice --&lt;/option&gt;
  
  &lt;/select&gt;      
        &lt;/div&gt;
  &lt;div class="filter_urun" id="filtre_urun"&gt;&lt;p&gt;Product:&lt;/p&gt;
  &lt;select id="filter_product" name="filtre_product[]" disabled="disabled" class="select_urun"  title="Select a product" multiple="multiple" size="5"&gt;
  &lt;option value="" data-filter-type="" selected="selected"&gt;
  -- Make a Choice --&lt;/option&gt;
  
  &lt;/select&gt;   
  
  &lt;/div&gt;
  &lt;/div&gt;   
  
  &lt;div class="part03_line03" id="part03_line03"&gt;
    &lt;div class="aramadugmesi" id="aramadugmesi"&gt; &lt;button type="submit" id="applyFilterButton"&gt;Apply Filters&lt;/button&gt;
  &lt;/div&gt;         
  &lt;/div&gt;
  &lt;/fieldset&gt;  
  &lt;/form&gt; 
  </code></pre>
  
  <p><strong>JAVASCRIPT</strong></p>
  
  <pre><code>&lt;script&gt;
  
  $(document).ready(function() { 
  
  $('#filter_region')
  .load('/textdata/region.txt');
  
  $('#filter_country')
  .load('/textdata/country.txt');
  
  
  $('#filter_sector')
  .load('/textdata/sector.txt');
  
  $('#filter_sector').change(function() {
  $('#filter_subsector').load("textdata/subsector/" + $(this).val() + ".txt",
  function(){
  $(this).attr('disabled',false);
  }
  );
  });
  
  $('#filter_subsector').change(function(){
  $('#filter_product').load(
  "textdata/subsector/product/" + $(this).val() + ".txt",
  function(){
  $(this).attr('disabled',false);
  }
  );
  });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>This Php coding is not working for me. It is not giving any results when I click Apply Filter. For example when I select Europe and North America in the selection box and click apply, I want all the companies which are in Europe OR North America to be fetched from database and listed. But it fetches no result. I guess it is a problem with php coding but I don't know whats wrong</p>