title: Codeigniter - Perform action if database query returns no results
body: <p>How can I return a value of 'no data found' if my query returns no results???</p>
  
  <p>This is my code:</p>
  
  <pre><code>    function getTerms($letter) {
  
  
      $this-&gt;db-&gt;select('term, definition');
      $this-&gt;db-&gt;from('glossary');
      $this-&gt;db-&gt;where(array('letter' =&gt; $letter));
  
      $query = $this-&gt;db-&gt;get();
  
      foreach ($query-&gt;result() as $row) {
          $data[] = array(
              'term' =&gt; $row-&gt;term,
              'definition' =&gt; $row-&gt;definition
          );
      }
  
      return $data;
  }
  </code></pre>
  
  <p>It currently returns the $data variable even if the query returns no results which is giving me php errors. How can I check that there are results before returning the $data array.</p>