我在一页中有两个模态。一个用于编辑,另一个用于创建。在这两个模式中都包含 select2 选项。以及我从数据库中获得的选项。我想将数据用于两个模态。但是我在模态创建中遇到错误,而模态编辑中没有错误。在模态创建中,它无法显示选择选项中的数据。谁能帮我?我试试这个 public function detail_produk(){ $data['item']=$this->admin_model->get_all_detail_produk(); $data['ukuran'] = $this->admin_model->get_ukuran(); $data['sidebar'] = $this->load->view('sidebar','',TRUE); $data['header'] = $this->load->view('header','',TRUE); $this->load->view('detail_produk', $data);}风景 <div class="modal fade" role="dialog" id="detail_user"><div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="form-group row"> <label class="col-sm-2 col-form-label">Ukuran</label> <div class="col-sm-10"> <select class="form-control select2" style="width: 100%;" id="ukuran"> <option selected="true" disabled="disabled">Pilih Ukuran</option> <?php foreach ($ukuran as $ukuran) { ?> <option value="<?php echo $ukuran['id'];?>"><?php echo $ukuran['size'];?></option> <?php } ?> </select> </div> </div> </form> </div><div class="modal-footer"> <button type="button" id="button-simpan" class="btn btn-primary mr-auto" >Simpan</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Kembali</button></div></div></div></div><div class="modal fade" role="dialog" id="tambah"><div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> </div>
1 回答
互换的青春
TA贡献1797条经验 获得超6个赞
foreach ($ukuran as $ukuran)
您不能使用相同的变量。做如下的事情
foreach ($ukuran as $value){
//now you can
echo $value['id'];
}
- 1 回答
- 0 关注
- 97 浏览
添加回答
举报
0/150
提交
取消