-2

我在控制器中有这样的功能。我需要将结果从$data1['hasil1']tampilInduk 插入。

public function sikap(){
    $person=$this->session->userdata('idperson');
    $data1['hasil1']=$this->M_Guru->tampilNik($person);

    $data2['hasil2']=$this->M_Guru->tampilInduk($data1);
    $this->load->view('sidebarGuru');
    $this->load->view('navbarGuru');
    $this->load->view('kompetensiSikap',$data1+$data2);
}

我有这样的模型代码

public function tampilInduk($data1){
        $this->db->select('induk');
        $this->db->from('kelas b');
        $this->db->join('siswa_kelas c','c.namakelas= b.namakelas','c.thnakademik=b.thnakademik','c.kdtingkat=b.kdtingkat','right');
        $this->db->where('nik',$data1);
        $data = $this->db->get(); //mengambil seluruh data
        return $data->result();
    }

public function tampilNik($person){
        $this->db->select('nik');
        $this->db->from('guru');
        $this->db->where('idperson',$person);
        $data=$this->db->get();
        return $data->row()->nik;
    }

但是错误说变量需要先转换为字符串。你能帮我如何将数组转换为字符串吗?

4

3 回答 3

1

这应该有效:

public function sikap(){
    $person=$this->session->userdata('idperson');
    $data1['hasil1']=$this->M_Guru->tampilNik($person);

    $data2['hasil2']=$this->M_Guru->tampilInduk($data1['hasil1']);
    $this->load->view('sidebarGuru');
    $this->load->view('navbarGuru');
    $this->load->view('kompetensiSikap',$data1+$data2);
}


   public function tampilInduk($nik){
        $this->db->select('induk');
        $this->db->from('kelas b');
        $this->db->join('siswa_kelas c','c.namakelas= b.namakelas','c.thnakademik=b.thnakademik','c.kdtingkat=b.kdtingkat','right');
        $this->db->where('nik',$nik);
        $data = $this->db->get(); //mengambil seluruh data
        return $data->result();
    }

public function tampilNik($person){
        $this->db->select('nik');
        $this->db->from('guru');
        $this->db->where('idperson',$person);
        $data=$this->db->get();
        return $data->row()->nik;
    }
于 2018-07-24T05:04:58.957 回答
0

您可以针对您的问题尝试此解决方案:

public function tampilInduk($data1) {
        $this->db->select('induk');
        $this->db->from('kelas b');
        $this->db->join('siswa_kelas c', 'c.namakelas= b.namakelas', 'c.thnakademik=b.thnakademik', 'c.kdtingkat=b.kdtingkat', 'right');
        $this->db->like('nik',$data1['hasil1']);
        $data = $this->db->get(); //mengambil seluruh data
        return $data->result();
    }

我希望它会有所帮助。

于 2018-07-24T04:52:47.860 回答
0

您可以使用$this->db->where('nik',$data1['hasil1']);而不是$this->db->where('nik',$data1);

于 2018-07-24T04:34:24.740 回答