title: how to combine query() and limit() methods in CodeIgniter
body: <p>Is it possible to do something like this in codeigniter:</p>
  
  <pre><code>publi function getcat($category_id)
  {
      $query = "(SELECT cat.id, cat.title ";
      $query = $query . "FROM bf_categories cat ";
      $query = $query . "WHERE cat.id=" . $category_id;
      $this-&gt;db-&gt;limit(2, 4);
      $records = $this-&gt;db-&gt;query($query);
      return $records-&gt;result();
  }
  </code></pre>
  
  <p>I've simplified the query just for demo purposes... but it's actually quite complex, which is why I've decided to use the <code>query()</code> method.</p>
  
  <p>But the limit clause is not being included in the query... I've verified by enabling the codeigniter profiler in my controller and I can see that the query is run with out any limit clause.</p>
  
  <p>Can you tell me how I can accomplish this using the <code>query()</code> method?</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>I've modified my model to look like this: </p>
  
  <pre><code>public function get_categories_and_products($limit=5, $offset=0, $category_id=null)
  {
      print "&lt;BR&gt;the function got the following offeset: $offset and limit: $limit";
      $query = "(SELECT cat.category_id, cat.title, cat.image_thumb, cat.deleted, cat.display_weight ";
              $query = $query."FROM bf_categories cat ";
              $query = $query."WHERE cat.parent_id=".$category_id;
      $query = $query." AND cat.category_id &lt;&gt;".$category_id;
      $query = $query.") UNION (";
      $query = $query."SELECT p.product_id, p.name, p.image_thumb, p.deleted , p.display_weight";
      $query = $query." FROM bf_product p ";
      $query = $query."Inner join bf_product_category cp ";
      $query = $query."on p.product_id=cp.product_id ";
      $query = $query."Where cp.category_id=".$category_id.") ?";
  
              $records = $this-&gt;db-&gt;query($query,array($this-&gt;db-&gt;limit(2, 4)));
              return $records-&gt;result();
       }
  </code></pre>
  
  <p>I've hardcoded the limit values for now... but ultimately, i'll be using the values that get passed into the method.  Unfortunately, this code still does not work. 
  According to the profiler, here's what's being executed: </p>
  
  <pre><code>(SELECT cat.category_id, cat.title, cat.image_thumb, cat.deleted, cat.display_weight FROM bf_categories cat WHERE cat.parent_id=3 AND cat.category_id &lt;&gt;3) UNION (SELECT p.product_id, p.name, p.image_thumb, p.deleted , p.display_weight FROM bf_product p Inner join bf_product_category cp on p.product_id=cp.product_id Where cp.category_id=3)
  
  SELECT * FROM (`bf_categories`) WHERE `category_id` = '3' LIMIT 4, 2
  </code></pre>
  
  <p>So it's creating two separate select statements. </p>