Seems like a common occurance this error on here, Looking at the answers I still cant quite work out why I'm getting an error.
I am getting the error
Fatal error: Call to a member function result() on a non-object on line 83
The line in question relates to this function in the Controller - This is what's creating the error.
$this->view_data['categories'] = $my_categories->result();
The function is below..
function _load_search_options()
{
// Get all the categories for the advanced search page
$my_categories = $this->Categories_model->get_all();
$this->view_data['categories'] = $my_categories->result();
// Get all the PRIMARY colours from teh tbl_colour_options
$my_colour_options = $this->Colours_model->get_all_primary();
$this->view_data['colour_options'] = $my_colour_options->result();
// Get all the colours from teh tbl_colour_options
$my_colour_options_all = $this->Colours_model->get_all();
$this->view_data['colour_options_all'] = $my_colour_options_all->result();
}
My Model is as follows...
function get_all()
{
$query_str = "
SELECT *
FROM categories
WHERE CATEGORIES_parent_id = 0
";
$results = $this->db->query($query_str);
$parents = $results->result();
foreach ($parents as $parent)
{
$children = array();
$query_str = "
SELECT *
FROM categories
WHERE CATEGORIES_parent_id = '$parent->CATEGORIES_id'
";
$children_results = $this->db->query($query_str);
$children_results = $children_results->result();
foreach($children_results as $children_result)
{
$children[$children_result->CATEGORIES_id] = $children_result->CATEGORIES_title;
}
$categories[$parent->CATEGORIES_title] = $children;
}
return $categories;
}
It's worth noting that running the SELECT query in MySQL on its own brings through some results.