我的功能在控制器上添加模型
$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 =偶数。
在视图上,修复条件,以便选择正确的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>