Welcome Guest, Not a member yet? Register   Sign In
undefined index error message
#1

[eluser]Luke D.[/eluser]
Hi all -

I am returning some data from a model to a controller - this is all pretty straightforwards - and I have coded stuff like this hundreds of times albeit not in CI, and this chunk of code keeps getting "Message: Undefined index: name."

The code is like this:
Code:
if($id=='root')
{
    $results = $this->Visitor->get_all_type($type, 'web01');
    foreach($results as $result) {
        $item[]['text']=$result['name'];
    }            
} else {
//blah blah...
}

$this->Visitor is a model accessing the database and that is working fine. In fact, the code is producing data, but there is this warning message and I don't see how $result['name'] could be unassigned. Heck, when I print_r($result['name'] it prints out the array but I still get the warning. How is this possible?

Luke
#2

[eluser]Randy Casburn[/eluser]
Let's take a look at the get_all_type() method.
#3

[eluser]Luke D.[/eluser]
Ok, here is the method as requested:

Code:
function get_all_type($type, $search_term='root')
    {
        $this->db->like('keyword', $search_term);
        $query = $this->db->get('web_pages');
        if($query->num_rows() > 0) {
            foreach($query->result() as $row) {
                $results[]['file_name'] = $row->file_name;
                $results[]['name'] = $row->name;
            }
        
        }
        return $results;
    }
#4

[eluser]Luke D.[/eluser]
Figured it out. Need to be explicit setting keys...




Theme © iAndrew 2016 - Forum software by © MyBB