将数组转换为代码点火器中的字符串



我在控制器中有一个这样的函数。我需要将结果从$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;
}

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

这应该有效:

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;
}

您可以尝试以下解决方案来解决您的问题:

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();
}

我希望这会有所帮助。

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

相关内容

  • 没有找到相关文章

最新更新