title: Need help Creating Table from query results
body: <p>I'm having trouble creating a table from my query results.
  I have this code:</p>
  
  <pre><code>// Model
  &lt;?php
      class Search_Employee extends CI_Model {
          function getAll() {
              $searchterm = $this-&gt;name = $_POST['empname'];
  
              $this-&gt;db-&gt;like('first_name', $searchterm);
              $this-&gt;db-&gt;or_like('last_name', $searchterm); 
  
              $q = $this-&gt;db-&gt;query("SELECT first_name, last_name, deparment.name FROM employee
                                     INNER JOIN deparment ON employee.department_id = department.id
                                     WHERE first_name LIKE '%" . $searchterm . "%' OR last_name LIKE '%" . $searchterm . "%'");
  
              if ($q = $this-&gt;db-&gt;get('employee'))
              {
                  if ($q-&gt;num_rows() &gt; 0) {
                      foreach ($q-&gt;result() as $row) {
                          $data[] = $row;
                      }
                      return $data;
                  } else {
                      echo "No results found.";
                      return array();
                  }
              } else {
                  echo sprintf("DB Query Failed: %s", $q);
                  return false;
              }
          }
      }
  </code></pre>
  
  <hr>
  
  <pre><code>// Controller
  class Employees extends CI_Controller {
      function search_employee()
      {
          $this-&gt;load-&gt;library('table');
          $this-&gt;load-&gt;model('search_employee');
  
          $data['main_content'] = 'display_employee';
          $data['rows'] = $this-&gt;search_employee-&gt;getAll();
  
          $this-&gt;load-&gt;view('includes/template', $data);
  
      }
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>// View
  &lt;h1&gt;Results&lt;/h1&gt;
  &lt;?php
  $this-&gt;table-&gt;set_heading('Name', 'Last Name', 'Department');
  $tmp = array ( 'table_open'  =&gt; '&lt;table border="0" cellpadding="2" cellspacing="1"&gt;' );
  $this-&gt;table-&gt;set_template($tmp);
  
  foreach ($rows as $r) :
      $this-&gt;table-&gt;add_row($r); ?&gt;
  endforeach;
  ?&gt;
  </code></pre>
  
  <p>I keep getting a </p>
  
  <pre><code>Fatal error: Call to a member function result() on a non-object in C:\xampp\htdocs\employees\application\views\display_employee.php on line 15
  Line 15
  </code></pre>
  
  <p>is the <code>foreach()</code> loop.</p>
  
  <p>Thank you very much in advance for your help.</p>