title: Codeigniter omit where clause for empty criterion
body: <p>I have a page for browsing db records. The viewer can filter records by category, author, and tags. I'm using a form instead of url segments for filtering records (it feels more secure because I can validate inputs.)</p>
  
  <p>For instance, when all form inputs are populated the query looks like this:</p>
  
  <pre><code>SELECT * FROM (`posts`) WHERE `category` = 'technolgy' AND `author` = 'lila' AND `tags` = 'ebook'
  </code></pre>
  
  <p>However if one input or more is empty, I get no results. For example:</p>
  
  <pre><code>SELECT * FROM (`posts`) WHERE `category` = '' AND `author` = 'lila' AND `tags` = '' 
  </code></pre>
  
  <p>I want the inputs to be optional so for example if just <code>author name</code> is entered, I can return records made by that author regardless of category and tags. How can I omit the <code>and where</code> clause if empty? </p>
  
  <p>Note: <code>or_where</code> clause is not the solution because it doesn't return a precise query if all filter inputs all filled.</p>
  
  <p>My Model</p>
  
  <pre><code>function filter($form_values)
      {                       
          $query = $this-&gt;db-&gt;get('posts');           
          $this-&gt;db-&gt;where($form_values); //adds clause to all array items
          return $query-&gt;result();        
      }
  </code></pre>
  
  <p>The function parameter is an array with input values from my view. Example,</p>
  
  <pre><code>$form_values = array('category' =&gt; $category, 'author' =&gt; $author, 'tags' =&gt; $tags);
  </code></pre>
  
  <p>and my View</p>
  
  <pre><code>$form_values = array (                  
                  'category' =&gt; $this-&gt;input-&gt;post('category'),
                  'author'   =&gt; $this-&gt;input-&gt;post('author'),
                  'tags'     =&gt; $this-&gt;input-&gt;post('tags')
              );
  
  $this-&gt;Records_model-&gt;filter($form_values);    
  </code></pre>
  
  <p>I know that in Codeigniter if <code>$_POST'</code> are empty they are set to <code>FALSE</code>. Can that be used to achieve what I'm trying? I'm not sure if I'm on the right track</p>