$num = $this->db->count_all_results('tbl_contactus');
return $num->result();
As the function name implies, count_all_results()
returns the count of table rows.
So $num
is of type integer, therefore not an object so calling $num->result()
is wrong (and pointless).
If you want the results, fetch them and count them later. Otherwise just return the count:
return $this->db->count_all_results('tbl_contactus');
Anyway, it's all in the manual, as I suggested in your previous question you should read it thoroughly before hacking code together. Or at least read it when you're stuck. Refernce for AR: http://ellislab.com/codeigniter/user-guide/database/active_record.html. In this case:
$this->db->count_all_results();
Permits you to determine the number of rows in a particular Active Record query. Queries will accept Active Record restrictors such as where(), or_where(), like(), or_like(), etc.