如何根据输入使用select来编辑id_semester的值?

问题描述 投票:0回答:1

我的功能在控制器上添加模型

$data['edit'] = $this->pengumuman->getEdit($id_pengumuman);

我的函数getEdit在Model上

$this->db->select('mp.id_pengumuman, mp.judul_pengumuman, mp.isi_pengumuman, mp.start_date, mp.end_date, 
            mp.thn_ajaran, mp.id_semester, mb.beasiswa, mp.date_created, mp.user_created, mp.is_publish')
        ->from('tbl_mst_pengumuman mp')
        ->join('tbl_mst_beasiswa mb', 'mp.id_beasiswa=mb.id_beasiswa', 'left')
        ->group_by('mp.id_pengumuman')
        ->where('mp.id_pengumuman', $id_pengumuman);
        return $this->db->get()->row();

我的表格在视图上

<div class="form-group">
<div class="col-sm-12">
 <label>Semester<span class="required">*</span></label>
  <select name="id_semester" id="id_semester" class="form-control input-sm">
   <option value="0">--Pilih Semester--</option>
   <option value="1" <?= ($edit->id_semester == @$edit->id_semester) ? "selected":""; ?>>Ganjil</option>
   <option value="2" <?= ($edit->id_semester == @$edit->id_semester) ? "selected":""; ?>>Genap</option>
  </select>
</div>
</div>

id_semester中,值1 =奇数,2 =偶数。问题是当id_semester的编辑值无法正确显示时。所有ID显示2 =偶数。

php html mysql codeigniter
1个回答
0
投票

在视图上,修复条件,以便选择正确的id_semester

<div class="form-group">
<div class="col-sm-12">
 <label>Semester<span class="required">*</span></label>
  <select name="id_semester" id="id_semester" class="form-control input-sm">
   <option value="0">--Pilih Semester--</option>
   <option value="1" <?= ($edit->id_semester == '1') ? "selected":""; ?>>Ganjil</option>
   <option value="2" <?= ($edit->id_semester == '2') ? "selected":""; ?>>Genap</option>
  </select>
</div>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.