Trying to show a category tree (with subcats and sub-subcats) Using this code: <?php $categories = get_categories(); foreach($categories as $category) { // Print the top level category echo $category->title .'<br />'; // get the sub categories $subcategories = get_categories($category->id); foreach($subcategories as $subcategory) { echo '- '. $subcategory->title. '<br />'; } } function get_categories($parent = 0) { $this->db->where('parent', $parent); $query = $this->db->get('bin_location'); return $query->result(); } ?> PHP: Getting: Fatal error: Call to a member function on a non-object in /home/domains/public_html/system/application/views/frontpage_view.php on line 25 Anyone have any ideas why I am having this problem?
You can't use $this-> in this context. First you have to do: $this->CI =& get_instance(); PHP: then using $this->CI->db->where('parent', $parent) won't produce any error.