CodeIgniter Forums
[SOLVED] "Undefined Index" Issues and Problems - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: [SOLVED] "Undefined Index" Issues and Problems (/thread-19013.html)



[SOLVED] "Undefined Index" Issues and Problems - El Forum - 05-25-2009

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

Code:
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:

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

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

Code:
$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);
        $this->load->view('app/footer');

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?


[SOLVED] "Undefined Index" Issues and Problems - El Forum - 05-25-2009

[eluser]TheFuzzy0ne[/eluser]
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:

Code:
echo $content[0]->name;



[SOLVED] "Undefined Index" Issues and Problems - El Forum - 05-25-2009

[eluser]phused[/eluser]
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.


[SOLVED] "Undefined Index" Issues and Problems - El Forum - 05-25-2009

[eluser]Dam1an[/eluser]
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