title: PHP Fatal error: Call to a member function row() on a non-object result_array() when I use SQL subquery
body: <p>I am using WAMP server 2.4.
  I am trying to get count of distinct months in database but getting this error "Call to a member function row() on a non-object result_array()". This is my code for my model class</p>
  
  <pre><code>public function get_current_month()
  {
  
      $this-&gt;db-&gt;select('(COUNT(DISTINCT  Month))' );
      $this-&gt;db-&gt;from('site_data');
      $this-&gt;db-&gt;where('year =(');
      $this-&gt;db-&gt;select('MAX(year )');
      $this-&gt;db-&gt;from('site_data)');
      $query = $this-&gt;db-&gt;get();
  
  
      return $query-&gt;result_array(); //error here
  
  }
  </code></pre>
  
  <p>I believe this has something to do with sub query in code because when I use this </p>
  
  <pre><code>public function get_current_month()
  {
  
      $this-&gt;db-&gt;select('(COUNT(DISTINCT  Month))' );
      $this-&gt;db-&gt;from('site_data');
      $this-&gt;db-&gt;where('year =2013');
      //$this-&gt;db-&gt;select('MAX(year )');
      //$this-&gt;db-&gt;from('site_data)');
      $query = $this-&gt;db-&gt;get();
  
  
      return $query-&gt;result_array();
  
  }
  </code></pre>
  
  <p>it is working just fine.
  I am using codeigniter</p>
  
  <p>Does anyone has idea what is going wrong here.</p>
  
  <p>This is the query which I tested in database it is working perfectly</p>
  
  <pre><code>SELECT (COUNT(DISTINCT MONTH))
  FROM site_data
  WHERE YEAR = ( 
      SELECT MAX(YEAR) 
      FROM site_data
  )
  </code></pre>