• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] "Undefined Index" Issues and Problems

#1
[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?

#2
[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;

#3
[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.

#4
[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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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