所以我试着在表单页面创建一个动态下拉菜单,当用户填写表单时,会有一个动态下拉菜单供用户选择某个特定的东西,一旦选中,它就可以保存到数据库中。但是当我测试它时,动态下拉菜单什么也没有显示,我该怎么修复它呢?
模型:
public function get_jenis_pekerjaan(){
$query = $this->db->get('jenis_pekerjaan');
return $query->result_array();
}
主计长:
public function job_type(){
$data['jenis_pekerjaan'] = $this->m_lowongan->get_jenis_pekerjaan();
$this->load->view('create_lowongan', $data);
}
public function store_lowongan(){
$user_name = $this->session->userdata('name');
$title = $this->input->post('title');
$lokasi = $this->input->post('lokasi');
$level_pekerja = $this->input->post('jenis_pekerjaan');
$pengalaman_kerja = $this->input->post('pengalaman_kerja');
$pendidikan = $this->input->post('pendidikan');
$alamat = $this->input->post('alamat');
$no_wa = $this->input->post('no_wa');
$no_telp = $this->input->post('no_telp');
$min_gaji = $this->input->post('min_gaji');
$max_gaji = $this->input->post('max_gaji');
$job_desc = $this->input->post('job_desc');
$created_at = date('y-m-d');
$status = 'draft';
$data = array(
'user_name' => $user_name,
'title' => $title,
'lokasi' => $lokasi,
'level_pekerja' => $level_pekerja,
'pengalaman_kerja' => $pengalaman_kerja,
'pendidikan' => $pendidikan,
'alamat' => $alamat,
'no_wa' => $no_wa,
'no_telp' => $no_telp,
'min_gaji' => $min_gaji,
'max_gaji' => $max_gaji,
'job_desc' => $job_desc,
'created_at' => $created_at,
'status' => $status,
);
$this->m_lowongan->input_data($data, 'lowongan');
redirect ('dashboard');
}
该视图:
<tr>
<td>Level Pekerjaan</td>
<td>
<select name="jenis_pekerjaan" id="jenis_pekerjaan" class="form-control">
<?php foreach($jenis_pekerjaan as $l) {?>
<option value="<?php echo $l['jenis_pekerjaan']?>"><?php echo $l['jenis_pekerjaan']?></option>
<?php }?>
</select>
</td>
</tr>
1条答案
按热度按时间uqxowvwt1#
我想我这样做是成功的。
1.我创建了一个函数来获取模型中的数据:
1.我在控制器中调用了该函数:
1.我在store函数中添加
$data_jp
来存储jenis_pekerjaan
的值:1.我编辑视图,使其看起来像这样的动态下拉列表:
它工作正常,显示
jenis_pekerjaan
表中的值,并将数据存储到数据库中:D