我的功能在控制器上添加模型
$data['edit'] = $this->pengumuman->getEdit($id_pengumuman);
我的函数getEdit on 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 =偶数。
答案 0 :(得分: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>