如何设置下拉列表的选定值?

时间:2018-10-11 09:42:35

标签: php html codeigniter

按提交按钮后,我的下拉列表将清除。我尝试更改但发生错误。

<select name="staff" id="staff" required>
    <option value="">Select Staff</option>
    <?php while($row_subject = mysql_fetch_array($query_subject)) { ?>
    <option value="<?php echo $row_subject['deo_code']; ($this->input->post('staff') == $row_subject['deo_code'] ? ' selected' : '') ?>">
    <?php echo $row_subject['deo_code']."-".$row_subject['deo_name'];?>
    </option>
    <?php } ?>
</select>

1 个答案:

答案 0 :(得分:-1)

您可以使用类似这样的东西:

<select name="staff" id="staff" required>
    <?php for($i = 1; $i <= 10; $i++) ?>
        <option value="<?php echo $i ?>" <?php $i == 2 ? 'selected' : '' ?>><?php echo $i ?< بزرگسال</option>
        <option value="">Select Staff</option>
</select>