0
對不起,我的英語不好。當我得到與數據庫相匹配的父類別id類別並插入到選擇菜單中時,我想更新它。看圖像波紋管:父母類別在codeigniter中更新時如何獲取id類別
我的數據庫是:
==========================================
kat_id | parent_kategori | kategori |
==========================================
1 | 0 | wanita |
2 | 1 | sandal wanita |
3 | 1 | sepatu wanita |
我的看法是:
<div class="input group">
<label>Kategori :</label>
<input type="text" name="kat" class="form-control" id="kat" placeholder="Nama Kategori" value="<?php echo $updatedata['kategori'];?>" required>
<input type="hidden" name="id" class="form-control" id="id_kat" value="<?php echo $updatedata['kat_id'];?>" required>
<br>
</div>
<div class="input group">
<label>Parent kategori :</label>
<?php echo form_dropdown('parent',$jabatan,$updatedata['kat_id']); ?>
<br>
</div>
我的控制器:
$update = $this->kategori_adm->get_categorie($id);
$update = $this->kategori_adm->ambil_data_employee($id);
$dd_jabatan = array();
foreach ($this->kategori_adm->master_jabatan() as $data_jabatan)
{
$dd_jabatan[$data_jabatan['kat_id']] = $data_jabatan['kategori'];
}
$this->data['jabatan']=$dd_jabatan;
$this->data['updatedata'] = $update;
$this->load->view('user_log_as_admin/header');
$this->load->view('user_log_as_admin/kategori/edit',$this->data);
$this->load->view('user_log_as_admin/footer');
和我的模型是
class kategori_adm extends CI_Model{
function master_jabatan(){
$this->db->order_by('kat_id');
$sql_jabatan=$this->db->get('kategori');
if($sql_jabatan->num_rows()>0){
return $sql_jabatan->result_array();
}
}
function ambil_data_employee($id){
$this->db->where('kat_id', array('parent_kategori' => 0));
$sql_employee=$this->db->get('kategori');
if($sql_employee->num_rows()>0){
return $sql_employee->row_array();
}
}
function get_categorie($id){
$query = $this->db->query("SELECT * FROM kategori WHERE kat_id='$id'");
return $query->row_array();
}
如何腳本應該的。我是CodeIgniter的新手 –
@MochammadDannysetyawan檢查更新後的答案 –
Thankyou先生。 alkhamdulillah –