CodeIgniter Forums

Full Version: [SOLVED] "Undefined Index" Issues and Problems
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I'm having trouble displaying certain data of an array, this is what my array is currently looking like:

Array ( [0] => stdClass Object ( [id] => 1 [wid] => 1 [name] => Homepage [date] => 0000-00-00 00:00:00 ) )

I'm trying to get the "name" value by using the following line of code in my view file:

echo $content[0]['name'];

The $content variable is passed from my controller to my view, this is what the code looks like:

$data = array(
                    'content' => $this->ConceptModel->get_concept($id),
                    'comments' => $this->ConceptModel->get_comments($id)
        $this->load->view('app/header', $header);
        $this->load->view('app/concept', $data);

When I load the page, it breaks and stop loading further as soon as it gets to the echo. Any idea why this could be occurring?

El Forum

What you have is an object inside of an array. I'm not sure why it needs to be in an array if there's only one object, but you should be accessing it like this:

echo $content[0]->name;

El Forum

That was a fast reply, thanks a lot for the clarification.

I'm using an object because the array will have more than one object in some cases.

El Forum

Is the contents of the array what is seen when you do print_r in the view, the controller or the model?

Edit: that was a fast reply, so much so 2 things happened before I posted