title: codeigniter Query Grouping returning all results from my table
body: <p>I'm using the CodeIgniter framework. I'm creating a search function for my companies CMS, the search has different inputs coming from a form. Is there a way to run query groups based on the <code>$_POST</code>input? I can run queries separate for example:</p>
  
  <pre><code>class Search_model extends CI_Model {
  
  public function get_results($search_term='default')
  {
      $cat = $_POST["col"];
      // Column Select:
      $col = 'id, dob, gender, app_date, tests_ordered, payment_method, cost, report_results, country';
  
      // Build the query.
      $database = $this-&gt;load-&gt;database('bookings_dev', TRUE)
          -&gt;select($col)
          -&gt;from('results')
                  -&gt;where($cat . ' ' . 'BETWEEN "'. date('Y-m-d', strtotime($_POST['sdate'])). '" and "'. date('Y-m-d', strtotime($_POST['edate'])).'"')
          -&gt;order_by($_POST["col"]);
  
      // Execute the query.
      $query = $database-&gt;get();
  
      // Return the results.
      return $query-&gt;result_array();
  }
  </code></pre>
  
  <p>Works fine ad returns the correct records (for example all records within the selected date range, my issue is when I try and expand the query to take other options into account I either get all records from the db or none. I've tried changing the order of the LIKE and WHERE clauses, I've tried OR_LIKE, OR_WHERE etc. Any pointers in the right direction will be greatly appreciated. I've read <a href="https://www.codeigniter.com/user_guide/database/query_builder.html" rel="nofollow noreferrer">CIs Query Builder Class Docs</a> but m officially stuck. here is my model:</p>
  
  <pre><code>&lt;?php
  </code></pre>
  
  <p>class Search_model extends CI_Model {</p>
  
  <pre><code>public function get_results($search_term='default')
  {
      $cat = $_POST["col"];
      // Column Select:
      $col = 'id, dob, gender, app_date, tests_ordered, payment_method, cost, report_results, country';
  
      // Build the query.
      $database = $this-&gt;load-&gt;database('bookings_dev', TRUE)
          -&gt;select($col)
          -&gt;from('results')
              -&gt;group_start()
                  -&gt;where($cat . ' ' . 'BETWEEN "'. date('Y-m-d', strtotime($_POST['sdate'])). '" and "'. date('Y-m-d', strtotime($_POST['edate'])).'"')
              -&gt;group_end()
              -&gt;or_group_start()
                  -&gt;or_like($_POST["col"], $_POST["terms"])
              -&gt;group_end()
          -&gt;order_by($_POST["col"]);
  
      // Execute the query.
      $query = $database-&gt;get();
  
      // Return the results.
      return $query-&gt;result_array();
      }
  }
  </code></pre>
  
  <p>What id like to achive is:
  SELECT $cols FROM results WHERE condtion 1 has input OR condition 2 input OR condition 3 etc etc
  Is this possible?</p>