title: search products by checkbox in ecommerce shoping cart system in codeigniter php
body: <p>I am using CodeIgniter to build ecommerce project in which i am working on search products from database by multiple filter parameters with checkboxes.</p>
  <p>But i am not getting correct results. First i have check Brand-&gt;Dell it gets two products , after that i checked Ram-&gt; 5 GB so it does not changes but i want it shows only 1 product of 5 GB Ram with DELL Brand.</p>
  <p><a href="https://i.stack.imgur.com/hxgYL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hxgYL.png" alt="enter image description here" /></a></p>
  <p><strong>Model</strong></p>
  <pre><code>    &lt;?php
      class ProductsM extends CI_Model {
      
      public function getRowsByCheck($keyword){
      if($keyword==&quot;&quot;)
      {
        $search_keuword = '';
      }
      else
      {
       $search_keuword = &quot;and brand IN ('&quot;.$keyword.&quot;') OR ram IN ('&quot;.$keyword.&quot;') OR price IN ('&quot;.$keyword.&quot;')&quot;; 
      }
  
  $query = $this-&gt;db-&gt;query(&quot;SELECT * FROM products WHERE products_id!='' &quot; . $search_keyword . &quot;&quot;);
      
            if($query-&gt;num_rows() &gt; 0){                       
          $product   = $query-&gt;result_array(); 
          return $product;               
          }       
          else{
              
              echo &quot;&lt;div class='btn-success btn-block' align='center'&gt;&lt;strong&gt;NO Related Product Found!!!&lt;/strong&gt;&lt;/div&gt;&quot;;
          }
       }
      }?&gt;
  </code></pre>
  <p><strong>Controller</strong></p>
  <pre><code>class ProductsC extends CI_Controller {
  public function fetchByCheck(){
     $output='';
      $keyword='';
      if($this-&gt;input-&gt;post('tmp')){
        $array = $this-&gt;input-&gt;post('tmp');
        $keyword = implode(&quot;','&quot;,$array);
      }
      $data = $this-&gt;productsM-&gt;getRowsByCheck($keyword);
         foreach ($data as $p) {
    $output.='&lt;div class=&quot;col-md-4&quot;&gt;
        &lt;div class=&quot;panel panel-info&quot;&gt;
            &lt;div class=&quot;panel-heading&quot;&gt;'.$p[&quot;name&quot;].'&lt;/div&gt;
            &lt;div class=&quot;panel-body&quot; align=center&gt;
            &lt;img src=&quot;'.base_url(&quot;assets/images/&quot;.$p['image']).'&quot; style=&quot;height:100px;&quot;&gt;
            &lt;/div&gt;
            &lt;div class=&quot;panel-heading&quot;&gt;Rs.'.$p[&quot;price&quot;].'
        &lt;a href=&quot;'.base_url().&quot;ProductsC/addToCart/&quot;.$p['id'].'&quot; class=&quot;btn btn-success&quot;&gt;Add To Cart&lt;/a&gt;
            Ram '.$p[&quot;ram&quot;].'GB&lt;/div&gt;
          &lt;/div&gt;
          &lt;/div&gt;';
         }
      echo   $output;
    }
  }?&gt;
  </code></pre>
  <p><strong>View</strong></p>
  <pre><code>div class=&quot;list-group&quot;&gt;
                  &lt;h3&gt;BRAND&lt;/h3&gt;
                  &lt;?php
                  foreach($brand_data as $row){?&gt; 
                    &lt;div class=&quot;list-group-item checkbox&quot;&gt;
                      &lt;label&gt;&lt;input type=&quot;checkbox&quot; class=&quot;common-selector brand searchType&quot;
                        value=&quot;&lt;?php echo $row['brand'];?&gt;&quot;&gt;&lt;?php echo $row['brand'];?&gt;&lt;/label&gt;  
                    &lt;/div&gt;
                &lt;?php } ?&gt;
              &lt;/div&gt;    
  
              &lt;div class=&quot;list-group&quot;&gt;
                  &lt;h3&gt;RAM&lt;/h3&gt;
                    &lt;?php
                  foreach($ram_data as $row){?&gt; 
                    &lt;div class=&quot;list-group-item checkbox&quot;&gt;
                      &lt;label&gt;&lt;input type=&quot;checkbox&quot; class=&quot;common-selector ram searchType&quot; 
                        value=&quot;&lt;?php echo $row['ram'];?&gt;&quot;&gt;&lt;?php echo $row['ram'];?&gt;&lt;/label&gt;  
                       &lt;/div&gt;
                 &lt;?php } ?&gt;
              &lt;/div&gt;  
  </code></pre>
  <p><strong>Script.js</strong></p>
  <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
    $(document).ready(function(){
  $('.searchType').on('click', function () {
    var tmp = [];
        $(&quot;input&quot;).each(function() {
            if ($(this).is(':checked')) {
            var checked = ($(this).val());
            tmp.push(checked);
          }
        });
    //alert(tmp);
  
  $.ajax({
                url:&quot;&lt;?php echo base_url();?&gt;ProductsC/fetchByCheck&quot;,
                method:&quot;POST&quot;,
                data:{tmp:tmp},
                success:function(data){
                  //alert(data);
                  $('#result').html(data);
                }
          });
  });
  });
  &lt;/script&gt;
  </code></pre>