簡體   English   中英

如何從codeigniter中的另一個表中獲取職位值

[英]How to get the job title value from another table in codeigniter

我有包含titlelokasilevel_pekerjalowongan表,我有包含company_idjob_titlejob_locjob_lvlapply_job表。 所以當用戶想要申請工作時,他們填寫申請表,一旦用戶提交了用戶已經填寫的申請表,我希望job_title表中的apply_job填充lowongan表中的title值。

Model:

public function apply_data($where, $data, $table){
        $this->db->where($where);
        $this->db->insert($table, $data);
    }

Controller:

public function store_apply($id){
        $data_lowongan['lowongan'] = $this->db->get_where('lowongan', ['id'=>$id])->result();

        $config['upload_path']      = './upload/';
        $config['allowed_types']    = 'pdf';
        $config['max_size']         = 2000;
        
        $this->load->library('upload', $config);

        if(!$this->upload->do_upload('pdf_file')){
            $error = array('error' => $this->upload->display_errors());

            $this->load->view('apply_form', $error);
        }else{
            $data_upload = $this->upload->data();

            $company_id = $this->input->post('company_id');
            $job_title  = $this->input->post('title');
            $user_name  = $this->session->userdata('name');
            $user_desc  = $this->input->post('user_desc');

            $data = array(
                'user_name'     => $user_name,
                'company_id'    => $company_id,
                'job_title'     => $job_title,
                'user_desc'     => $user_desc,
                'pdf_file'      => $data_upload['file_name']
            );

            $where = array(
                'company_id'    => $company_id,
            );

            $this->m_lowongan->apply_data($where, $data, 'apply_job');
            
            redirect('dashboard');
        }
    }

只需將job_title值替換為您的$data數組,其中包括您要通過apply_data()插入的所有字段:

public function store_apply($id) {

    // This line doesn't seem to do anything
    $data_lowongan['lowongan'] = $this->db->get_where('lowongan', ['id'=>$id])->result();

    // Get the lowongan row based on the parsed id
    $lowongan = $this->db->get_where('lowongan', ['id' => $id])->row();

    // The rest of your code…

    $data = array(
        'user_name'  => $user_name,
        'company_id' => $company_id,
        'job_title'  => $lowongan->title, // Get the title from the $lowongan query
        'user_desc'  => $user_desc,
        'pdf_file'   => $data_upload['file_name']
    );

    // The rest of your code…

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM