我正在一页上工作,那里有很多下拉列表和一个文本字段,我从中添加一个用户并为该用户选择一些下拉列表,然后将其发送到数据库中,然后成功插入。编辑该用户,当我单击“编辑”时,它应在我选择插入的下拉菜单中打印所有选定的下拉菜单,其他应保持不变。 我的价值在于进入数组。.我需要知道如何将数组打印到下拉列表中。
Array
(
[0] => Array
(
[printprofiles_id] => 1
[profilename] => Peter
[description] =>
[printer] => 3
[report_id] => 0
[profile_id] => 1
)
[1] => Array
(
[printprofiles_id] => 2
[profilename] => Peter
[description] =>
[printer] => 4
[report_id] => 1
[profile_id] => 1
)
[2] => Array
(
[printprofiles_id] => 3
[profilename] => Peter
[description] =>
[printer] => 5
[report_id] => 2
[profile_id] => 1
)
[3] => Array
(
[printprofiles_id] => 4
[profilename] => Peter
[description] =>
[printer] => 6
[report_id] => 3
[profile_id] => 1
)
[4] => Array
(
[printprofiles_id] => 5
[profilename] => Peter
[description] =>
[printer] => 7
[report_id] => 4
[profile_id] => 1
)
)
这是我的标准代码
public function get_profilesitems_by_id($id){
$query = $this->db->get_where('setup_printprofiles', array('profile_id' => $id));
return $result = $query->result_array();
}
这是我的控制器代码
public function printprofilesedit($id = 0){
if($this->input->post('submit')){
$this->form_validation->set_rules('profilename', 'profilename', 'trim|required');
if ($this->form_validation->run() == FALSE) {
$data['all_printers'] = $this->setup_model->get_all_printers(); // In dropdown value is coming from another table...
$data['all_profiles'] = $this->setup_model->get_all_profiles();
$data['profile'] = $this->setup_model->get_printprofiles_by_id($id);
$data['profileitem'] = $this->setup_model->get_profilesitems_by_id($id); // In this there is an array which I showed above...
$data['view'] = 'admin/setup/printprofilesedit';
$this->load->view('admin/layout', $data);
}
else{
$options = array(
'report_id' => $this->input->post('report_id_'.$i),
'printer' => $this->input->post('printer_'.$i),
);
$this->setup_model->edit_printprofiles($options);
}
}
if($options){
$this->session->set_flashdata('msg', 'Record is Added Successfully!');
redirect(base_url('admin/setup/printprofiles'));
}
else{
$data['all_printers'] = $this->setup_model->get_all_printers(); // In dropdown value is coming from another table...
$data['all_profiles'] = $this->setup_model->get_all_profiles();
$data['profile'] = $this->setup_model->get_printprofiles_by_id($id);
$data['profileitem'] = $this->setup_model->get_profilesitems_by_id($id); // In this there is an array which I showed above...
$data['view'] = 'admin/setup/printprofilesedit';
$this->load->view('admin/layout', $data);
}
}
这是我的printprofilesedit.php,其中有HTML代码...我仅显示了4个下拉列表,但下拉列表超过50个。正如我提到的,只有那些我在插入时选择的下拉菜单才能填充。
<tr class="evenrow">
<td align="center"><input type="hidden" name="report_id_0" id="report_id_0" value="0">0</td>
<td>Default printing destination</td>
<td>
<select name="printer_0" id="printer" class="form-control" title="">
<option value="">Browse Support</option>
<?php foreach ($all_printers as $printer): ?>
<option value="<?= $printer['printer_id']?>"><?= $printer['name']?> </option>
<?php endforeach ?>
</select>
</td>
</tr>
<tr class="evenrow">
<td align="center"><input type="hidden" name="report_id_1" id="report_id_1" value="1">1</td>
<td>Customer Balance</td>
<td>
<select name="printer_1" id="printer" class="form-control" title="">
<option value="">Default</option>
<?php foreach ($all_printers as $printer): ?>
<option value="<?= $printer['printer_id']?>" ><?= $printer['name']?></option>
<?php endforeach ?>
</select>
</td>
</tr>
<tr class="evenrow">
<td align="center"><input type="hidden" name="report_id_2" id="report_id_2" value="2">2</td>
<td>Aged Customer Analysis</td>
<td>
<select name="printer_2" id="printer" class="form-control" title="">
<option value="">Default</option>
<?php foreach ($all_printers as $printer): ?>
<option value="<?= $printer['printer_id']?>"><?= $printer['name']?></option>
<?php endforeach ?>
</select>
</td>
</tr>
<tr class="evenrow">
<td align="center"><input type="hidden" name="report_id_3" id="report_id_3" value="3">3</td>
<td>Customer Details Listing</td>
<td>
<select name="printer_3" id="printer" class="form-control" title="">
<option value="">Default</option>
<?php foreach ($all_printers as $printer): ?>
<option value="<?= $printer['printer_id']?>"><?= $printer['name']?></option>
<?php endforeach ?>
</select>
</td>
</tr>
<tr class="evenrow">
<td align="center"><input type="hidden" name="report_id_4" id="report_id_4" value="4">4</td>
<td>Price Listing</td>
<td>
<select name="printer_4" id="printer" class="form-control" title="">
<option value="">Default</option>
<?php foreach ($all_printers as $printer): ?>
<option value="<?= $printer['printer_id']?>"><?= $printer['name']?></option>
<?php endforeach ?>
</select>
</td>
</tr>