不能将相同的数据用作不同模式框中的选项



我在一个页面中有两个模态。一个用于编辑,另一个用于创建。在两种模式中,包含select2选项。还有我从数据库中得到的选项。我想使用这两个模态的数据。但我在模态创建中遇到错误,在模态编辑中没有错误。在模态创建中,它不能在select选项中显示数据。有人能帮我吗?

我试试这个

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">&times;</button>
</div>
<div class="modal-body">
<form id="form1">
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Ukuran</label>
<div class="col-sm-10">
<select class="form-control select2" style="width: 100%;" id="ukuran_id">
<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-tambah" class="btn btn-primary mr-auto" >Tambah</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Kembali</button>
</div>
</div>

谢谢:(

foreach ($ukuran as $ukuran)

不能使用相同的变量。做一些类似于跟随的事情

foreach ($ukuran as $value){
//now you can
echo $value['id'];
}

相关内容

  • 没有找到相关文章

最新更新