简体   繁体   中英

A PHP Error was encountered Severity: Notice Message: Undefined property: stdClass::$moderator_id, using codeigniter

hey guys i am new in codeigniter and am working on an application in which i have to fecth data from mysql database,for this purpose i make two views for and two functions in controller to handle views . . the problem is that i got error in one view while in the other view its work fine . . . both view has same code. . . where is the mistake pls help . .

code in both views

 <?php foreach ($rows as $row):?>
            <tr>
                <td><?php echo anchor("Home/edit_moderator/" . $row->member_id, 'Edit'); ?></td>
                <td><a href="<?php echo site_url("dbcont/deletemoderator/" . $row->member_id);?>" onclick="return confirm('Delete content?');">Delete</a></td>
                <td><?php echo $row->member_name;  ?></td>
                <td><?php echo $row->moderator_id;  ?></td>
                <td><?php echo $row->kcc_branch;  ?></td>
                <td><?php echo $row->father_name;  ?></td>
                <td><?php echo $row->address;  ?></td>
                <td><?php echo $row->date;  ?></td>
            </tr>
            <?php endforeach; ?>

the error is in when i fetch moderator_id

<td><?php echo $row->moderator_id;  ?></td>

in the first view it fetched but in second view it doesn't . .

EDIT :

Here is the model

function get_moderators(){ 

    $select =   array(
                    'member_id', 
                    'member_name', 
                    'father_name', 
                    'date', 
                    'kcc_branch', 
                    'date_of_birth', 
                    'address', 
                    'phone', 
                    'mobile', 
                    'occupation', 
                    'pan', 
                    'bank_name', 
                    'bank_acc_no', 
                    'bank_branch', 'moderator'
    );

$this->db->select($select); 
$this->db->where('moderator', 1); 
$q = $this->db->get('tbl_members'); 
    if($q->num_rows() > 0) { 
        foreach ($q->result() as $row) { 
            $data[] = $row; 
        }
        return $data; 
    } 
}

i got my answer . . my mistake is i am not selecting moderator_id in select query . .here is the answer thanx for answering guys . .

function get_moderators(){ 

$select =   array(
                'member_id',
                'moderator_id', 
                'member_name', 
                'father_name', 
                'date', 
                'kcc_branch', 
                'date_of_birth', 
                'address', 
                'phone', 
                'mobile', 
                'occupation', 
                'pan', 
                'bank_name', 
                'bank_acc_no', 
                'bank_branch', 'moderator'
);


$this->db->select($select); 
$this->db->where('moderator', 1); 
$q = $this->db->get('tbl_members'); 
if($q->num_rows() > 0) { 
    foreach ($q->result() as $row) { 
        $data[] = $row; 
    }
    return $data; 
} 
}

you can get rid of the select array and just use

$this->db->select('*');

should work as well

I had a similar error and it turned out that my database select statement was wrong. this was the bad one:

$this->db->select('field1', 'field2', 'field3', 'field4'); //bad code

this is the right way to do it:

$this->db->select('field1, field2, field3, field4'); //good

or

$this->db->select('*'); //still good

best regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM