我有一个包含select option
输入的编辑表单,我想根据条件选择默认选项。那就是:从数据库预选选项值
<select class="form-control locationid" id="locationid" name="locationid" required>
<option value="" disabled selected> Select branch</option>
<option data-id="0" value="0">NONE</option>
<?php foreach ($vendor as $v) { ?>
<option data-id="<?php echo $v['location_id']; ?>" value="<?php echo $v['location_id']?>" ><?php echo $v['name'] ;?></option>
<?php };?>
</select>
我的控制器:
$this->db->select("d.user_id as id, d.plate_number as plate_number, d.current_lat as lat, d.current_lon as lon, d.created_on as created_on, d.updated_on as updated_on, d.available as available, d.location_id as location_id, u.user_name as name, u.user_email as email, u.user_phone as phone, v.name as location_name");
$this->db->from('user_driver as d');
$this->db->join('user as u', 'd.user_id = u.user_id','left');
$this->db->join('vendor_location as v', 'd.location_id = v.location_id','left');
$query = $this->db->get();
$data['driver'] = $query->result_array();
$this->db->select("location_id, name");
$this->db->from('vendor_location');
$query2 = $this->db->get();
$data['vendor'] = $query2->result_array();
的user_driver
表包含location_id
在vendor_location
表相关location_id
列列。我怎样才能使select option
表显示现有location_id
表中的user_driver
表以及来自vendor_location
表的选项?目前,上面的代码仅显示禁用选项Select branch
。
? –
来自'user_driver'表列'location_id'中的现有值。由于它是一个编辑窗体,因此它应该显示现有值@SanoojT – may
,因为它是一个编辑窗体,您有一个要编辑的ID,并且我没有看到任何'$ this-> db-> where(' ID',$ ID);'在你的代码中选择值 –