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
public function get_current_month()
{
$this->db->select('(COUNT(DISTINCT Month))' );
$this->db->from('site_data');
$this->db->where('year =(');
$this->db->select('MAX(year )');
$this->db->from('site_data)');
$query = $this->db->get();
return $query->result_array(); //error here
}
I believe this has something to do with sub query in code because when I use this
public function get_current_month()
{
$this->db->select('(COUNT(DISTINCT Month))' );
$this->db->from('site_data');
$this->db->where('year =2013');
//$this->db->select('MAX(year )');
//$this->db->from('site_data)');
$query = $this->db->get();
return $query->result_array();
}
it is working just fine. I am using codeigniter
Does anyone has idea what is going wrong here.
This is the query which I tested in database it is working perfectly
SELECT (COUNT(DISTINCT MONTH))
FROM site_data
WHERE YEAR = (
SELECT MAX(YEAR)
FROM site_data
)