赞
踩
- echo '<div class="text-nav-1 required "><div>' . _('在职状态') . ':</div>
- <select name="work_status">';
- // 定义选项数组
- $options = [
- 'all' => _('全部'),
- 'inwork' => _('在职'),
- 'levwork' => _('离职'),
- ];
- // 检查 $_POST['work_status'] 是否已设置,并赋予相应的默认值
- $selectedStatus = isset($_POST['work_status']) ? $_POST['work_status'] : 'all';
- foreach ($options as $value => $label) {
- // 判断当前选项是否为选中状态
- $selected = ($value == $selectedStatus) ? ' selected="selected"' : '';
- echo '<option value="' . $value . '"' . $selected . '>' . $label . '</option>';
- }
- echo '</select></div>';
- if (isset($_POST['work_status']) and $_POST['work_status'] != '' and $_POST['work_status'] != 'all') {
- $sql = $sql . " and work_status " . LIKE . " '%" . $_POST['work_status'] . "%' ";
- }
2、从html嵌套php
- <div class="text-nav-1 required ">
- <div><?php echo _('在职状态'); ?>:</div>
- <select name="work_status">
- <?php
- // 定义选项数组
- $options = [
- 'all' => _('全部'),
- 'inwork' => _('在职'),
- 'levwork' => _('离职'),
- ];
- // 检查 $_POST['work_status'] 是否已设置,并赋予相应的默认值
- $selectedStatus = isset($_POST['work_status']) ? $_POST['work_status'] : 'all';
- foreach ($options as $value => $label) {
- // 判断当前选项是否为选中状态
- $selected = ($value == $selectedStatus) ? ' selected="selected"' : '';
- ?>
- <option value="<?php echo htmlspecialchars($value); ?>" <?php echo $selected; ?>><?php echo htmlspecialchars($label); ?></option>
- <?php
- }
- ?>
- </select>
- </div>
- <?php
- $query = "SELECT DISTINCT employee_num FROM hr_employees";
- $result = DB_query($query, $db);
- // 2. 处理查询结果
- $options = [];
- while ($row = DB_fetch_array($result)) {
- // 假设您希望使用工作状态的实际值作为选项值,而显示的文本则进行一些转换或直接使用
- // 这里简化处理,直接使用employee_num值作为选项值和显示文本
- $options[$row['employee_num']] = $row['employee_num'];
- }
- // 添加“全部”选项
- $options = ['all' => _('全部')] + $options;
- // 3. 检查 $_POST['employee_num'] 是否已设置,并赋予相应的默认值
- $selectedStatus = isset($_POST['employee_num']) ? $_POST['employee_num'] : 'all';
- echo '<div class="text-nav-1 required "><div>' . _('工号') . ':</div>
- <select name="employee_num">';
- // 4. 生成下拉菜单
- foreach ($options as $value => $label) {
- $selected = ($value == $selectedStatus) ? ' selected="selected"' : '';
- echo '<option value="' . $value . '"' . $selected . '>' . $label . '</option>';
- }
- echo '</select></div>';
- ?>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。