【发布时间】:2016-09-26 18:30:48
【问题描述】:
$output 数组返回选项 vlaues 用于我打印为 <?php print_r($store);?> 的选择标记,当我尝试更新此表单时,我需要将 store 显示为选定值,并且选择列表必须具有其他现有与之前相同的值来自$output。
型号:
public function getStore() {
$this->db->select('*');
$store = $this->db->get('tbl_store_info');
$data = $store->result();
$output = array();
$output[]='<option value="" disabled selected>Select Store</option>';
foreach ($data as $row) {
$output[]= '<option value="' . $row->store_id . '">' . $row->store . '</option>';
}
return $output;
}
控制器:
public function editEmployee($id='') {
$empData= $this->CommonModel->getEmployee_by_ID($id);
$data['emp_list'] = $empData[0];
$data['store']= $this->CommonModel->getStore();
$data['user_role']= $this->CommonModel->getUserRole();
$data['msg']= $this->session->flashdata('usermsg');
$this->load->view('common/topnav');
$this->load->view('common/sidebar');
$this->load->view('common/header');
$this->load->view('common/title-header');
$this->load->view('employee/editEmployee',$data);
$this->load->view('common/footer');
}
查看:
<div class="form-group col-sm-5">
<label for="store">Store:</label>
<select class="form-control" id="store" name="store" required>
<option value="<?php echo $emp_list->store_id; ?>" selected><?php echo $emp_list->store; ?></option>
<?php print_r($store);?>
</select>
</div>
我只想将此 <option value="<?php echo $emp_list->store_id; ?>" selected><?php echo $emp_list->store; ?></option> 作为选定值。
【问题讨论】:
-
不清楚您想要实现什么以及您是如何尝试的。你能用其他/更清楚的话重新问你的问题吗?并粘贴更多相关代码?
-
我用更清晰的文字编辑了问题,请看@Jeff
-
仍然没有足够的代码来找出你在这里做什么。我已经可以说的一件事是,
print_r($store)不是正确的选择。创建一个foreach($store as $html)并回显$html。
标签: php html codeigniter