为什么呢?消息:未定义的属性:stdClass :: $ nik

时间:2019-03-21 04:37:11

标签: php codeigniter model

请帮助我在显示数据时遇到问题,

//Model
public function ambiluser()
{
    $user_id = $this->session->userdata('user_id');
    $this->db->select('*');
    $this->db->from('biodata');
    $this->db->where('id', $user_id);
    $sec_qry=$this->db->get();
    return $result=$sec_qry->result();
}

查看

foreach ($user as $row) 
 <td><?php echo $row->nik; ?></td>

1 个答案:

答案 0 :(得分:0)

首先,您应该检查查询是否返回任何结果!像这样:

if($sec_qry->num_rows() > 0){
    return $sec_qry->result();
}
return false;

您认为第二点:

<?php if( $user && !empty($user) ) :?>
    <?php foreach( $user as $row ) :?>
        <td><?=$row->nik;?></td>
    <?php endforeach;?>
<?php endif;?>