作为数组连接codeigniter传递数据

6qqygrtg  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(279)

请问,有谁能帮我修复代码显示数据数组时,我想加入和操作2查询作为一个得到。
这是我的控制器:

public function pegawai()
{
    $data['pegawai'] = $this->Ajax_model->pegawai_get();
    $this->load->view('ajax/pegawai', $data);
}

这是我的模型:

//get modal search data
public function pegawai_get($pegawai_id = TRUE)
{
    $this->db->select('m_riwayat_kepangkatan.*, m_pegawai.nip, m_pegawai.nama, r_golongan.golongan, r_golongan.jenis_pangkat');
    $this->db->from('m_riwayat_kepangkatan');
    $this->db->join('m_pegawai', 'm_pegawai.id = m_riwayat_kepangkatan.pegawai_id');
    $this->db->join('r_golongan', 'r_golongan.id = m_riwayat_kepangkatan.golongan_id');
    $this->db->order_by("pegawai_id", "asc");

    $query1 = $this->db->get();
    return $query1->result_array();

    $this->db->select('m_riwayat_jabatan.*, m_pegawai.nip, m_pegawai.nama, m_opd.nama_opd, m_unit_kerja.unit_kerja');
    $this->db->from('m_riwayat_jabatan');
    $this->db->where("m_pegawai.id ='$pegawai_id'");
    $this->db->join('m_pegawai', 'm_pegawai.id = m_riwayat_jabatan.pegawai_id');
    $this->db->join('m_opd', 'm_opd.id = m_riwayat_jabatan.opd_id');
    $this->db->join('m_unit_kerja', 'm_unit_kerja.id = m_riwayat_jabatan.unit_kerja_id');
    $this->db->order_by("pegawai_id", "asc");

    $query2 = $this->db->get();
    foreach ($query2->result_array() as $row2){
        //$pegawai_id    = $row2["pegawai_id"];
        //$nip           = $row2["nip"];
        //$nama          = $row2["nama"];
        $nama_opd      = $row2["nama_opd"];
        $unit_kerja    = $row2["unit_kerja"];
    }
    return $query2->result_array();
}

但我的数据是这样的:

"data": [
    {
        "id": "1",
        "pegawai_id": "1",
        "instansi": "null",
        "keterangan_instansi": null,
        "jenis_pegawai_id": "1",
        "golongan_id": "null",
        "tmt": "null",
        "no_sk": "null",
        "tgl_sk": "0000-00-00",
        "penetap_sk": null,
        "gaji_pokok": null,
        "dasar_keputusan": null,
        "scan_sk": null,
        "is_verified": "1",
        "input_tipe": "1",
        "created_at": "2017-12-14 08:32:05",
        "updated_at": "2018-02-20 09:05:07",
        "nip": "197207032007011024",
        "nama": "Abdullah",
        "golongan": "null",
        "jenis_pangkat": "null"
    },

它只是查询1的显示值。我还想计算query2内部数据的值,比如“nama\u opd”和“unit\u kerja”。看来我少了点什么。

b09cbbtk

b09cbbtk1#

看一看 return $query1->result_array(); . 您已在第二个查询之前返回了它

相关问题