使用foreach codeigniter从数据库中获取数据

时间:2013-11-04 08:41:45

标签: php mysql database codeigniter

我的项目有错误,你能帮我吗?这是我的代码:

$q_cek_login = $this->db->get_where('tbl_karyawan', array('username' => $u, 'password' => $p));
if(count($q_cek_login->result())>0)
{
    foreach($q_cek_login->result() as $qck)
    {

        if($qck->id_jabatan==1)
        {
            foreach($q_cek_login->result() as $qad)
            {
                $sess_data['logged_in'] = 'yesGetMeLogin';
                $sess_data['username'] = $qad->username;
                $sess_data['nama_pengguna'] = $qad->nama;
                $sess_data['id_jabatan'] = $qad->id_jabatan;
                $this->session->set_userdata($sess_data);
            }
            //header('location:'.base_url().'pemesanan/pending');
        }
    }
}

然后我收到此错误:

A PHP Error was encountered

严重性:注意

消息:未定义的属性:stdClass :: $ id_jabatan

文件名:models / model_digor.php

行号:26

txu all .............

1 个答案:

答案 0 :(得分:0)

尝试这样写 -

if(isset($qck->id_jabatan) && $qck->id_jabatan==1)