title: How to use where when using custom query in Codeigniter
body: <p>I am using codeigniter for my database application. I am not sure if it is possible to use get_where for custom query in codeigniter database class. </p>
  
  <p>This is my query</p>
  
  <pre><code>  $this-&gt;db-&gt;query("select model, varient, (select color from mtbl_colors where mtbl_colors.colorid=mtbl_vehicles.colorid) as color from mtbl_vehicles");
  </code></pre>
  
  <p>Now if i want to filter the above using where clause, I am using the query as </p>
  
  <pre><code>  function getVehicles($model='',$varient='')
   {
        if($model!='')
            {
              $q=$this-&gt;db-&gt;query("select model,varient,(select color from mtbl_colors where
              mtbl_colors.colorid=mtbl_vehicles.colorid) as color from mtbl_vehicles 
              where model='$model'")-&gt;result();
              return $q;
             }
         elseif($varient!='')
            {
           $q=$this-&gt;db-&gt;query("select model,varient,(select color from mtbl_colors where
              mtbl_colors.colorid=mtbl_vehicles.colorid) as color from mtbl_vehicles 
              where varient='$varient'")-&gt;result();
              return $q;
             }
      }
  </code></pre>
  
  <p>This is only an example, where i have to write all conditions for each where conditions. So, I may be missing some thing in codeigniter which can accomplish such multiple where conditions more easier than i am using right now.</p>
  
  <p>EDIT::::</p>
  
  <p>after suggestion from @Yan I tried as follows </p>
  
  <pre><code> function getVehicles($where_clause='',$where_value='') {
      $sql = "select model,varient,(select color from mtbl_colors where
      mtbl_colors.colorid=mtbl_vehicles.colorid) as color from mtbl_vehicles";
     $where_clause=array("varient", "model", "colorid");
     $where_value=array("MAGNA 1.4", "SANTRO", "3")
  
      if (!empty($where_clause) &amp;&amp; !empty($where_value)) {
        $sql .= " where $where_clause = ?";
       return $this-&gt;db-&gt;query($sql, $where_value)-&gt;result();
      }
     return false;
    }
  </code></pre>
  
  <p>I received a database error saying "invalid column value Aarray"</p>
  
  <p>as my intention was to implement multiple condition to generate results as per my filter options.</p>