对不起我的英语不好。当我获得与数据库匹配并插入选择菜单的父类别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();
}
答案 0 :(得分:1)
让我们假设这是表:
+----+----------------+-----------------+
| id | category_name | parent_category |
+----+----------------+-----------------+
| 1 | Main | 0 |
+----+----------------+-----------------+
| 2 | Under Main | 1 |
+----+----------------+-----------------+
| 3 | Under Main too | 1 |
+----+----------------+-----------------+
然后选择所有包含parent_category = 0
的类别,您可以使用AJAX获取parent_category
所有类别等于所选类别的ID。
试试这个: Populate another select dropdown from database based on dropdown selection