undefined index error message

[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:
    $results = $this->Visitor->get_all_type($type, 'web01');
    foreach($results as $result) {
} 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?


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

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

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;

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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.