[add_library form]
<select name="employee_id" class="form-control">
<option value="">Select Employee.....</option
<?php
if (!empty($employee_info) && is_array($employee_info)){
foreach ($employee_info as $emp_info) {
// blow option of compare db id and select option value ?>
<option <?php echo ($emp_info->employee_id==$library_info->employee_id ) ? 'selected' : ''; ?>
value="<?php echo $emp_info->employee_id; ?>">
<?php echo $emp_info->first_name . ' ' . $emp_info->last_name ?>
</option>
<?php
}
}
?>
</select>
这是前端的屏幕截图。是开发中的新手。提前感谢您的帮助。 this is the pic of front end
答案 0 :(得分:0)
我不完全确定你是如何设置的,因为我不会这样做。但试试这个:
<select name="employee_id" class="form_control">
<option value="">Select Employee...</option>
<?php
if (!empty($employee_info)) { // Left out the is_array. You can check one or the other. empty only checks arrays. Can include it to be thorough
foreach ($employee_info AS $ei) {
echo '<option value="' . $ei->employee_id . '"';
echo ($ei->employee_id == $library_info->employee_id) ? ' SELECTED ' : '' . '>';
echo $ei->first_name . ' ' . $ei->last_name;
echo '</option>'.PHP_EOL;
}
}
?>
</select>
可能需要稍微调整一下。