eeek
eeek

Reputation: 307

Codeigniter, Trying to get property of non-object

I have a image hosting site in CI with an image view file (working well) and an image album one, however the album view is producing the following error 'Trying to get property of non-object'. I've tried searching but cant see what I'm doing wrong.

The area in my view which has this issue is (this line 'if($row->id == $id_array[$key]):'):

<?php if(count($records_array) != 1) : ?>
<div class="album-images">

<?php $i = 0; $links_array = array(); ?>
    <?php foreach ($records_array as $key => $records) {
    if(isset($records)) : foreach($records as $row) : ?>

        <?php if($row->id == $id_array[$key]):   ?>
        <?php $i++; ?>
        <?php

        //get array of ids for linking
        foreach ($id_array as $key => $ids) {
            array_push($links_array, alphaID($id_array[$key]));
        }

My other view has the exact same code which is why it's so strange.

Here's the content of records_array[] : http://pastebin.com/6pyTCBSH

And the id_array[] (contains the album images id's)

Array
(

    [0] => 2738
    [1] => 2758
)

The records_array is used at the top of the file is that's relevant http://pastebin.com/yF2yXrxK

Can anyone see why this is happening? The error outputs about 25-30times down the page.

Upvotes: 0

Views: 4027

Answers (1)

kba
kba

Reputation: 19466

The error "Trying to get property of non-object" mean that you're trying to access a variable or method on something that isn't an object. In this case, you're trying to access the variable id from $row, but $row isn't an object.

Depending on where the data comes from, perhaps it's an array, in which case you should access the id property as $row['id'].

In case this fails as well, I'd suggest you do print_r($row) to figure out what exactly $row contains.

Upvotes: 4

Related Questions