I have lowongan
table that contains title
, lokasi
, and level_pekerja
, and i have apply_job
table that contains company_id
, job_title
, job_loc
, and job_lvl
. So when the user want to apply the job, they fill the apply form, and once the user submitted the apply form that user already fill, i want the job_title
in the apply_job
table is filled with the title
value from the lowongan
table.
The Model :
public function apply_data($where, $data, $table){
$this->db->where($where);
$this->db->insert($table, $data);
}
The 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');
}
}
CodePudding user response:
Just replace the job_title
value into your $data
array, which includes all the fields you're going to insert through 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…
}