我找不到如何從MYSQL 把3個option load出來的方法,只能在view上hardcode印出來,現在的方法是做到我要的效果,但如果我的option是幾十個,就會很長,請問有解決方法嗎?
mysql setting
create
<div class="form-group col-md-6">
<label for="action_unit">Action Unit</label>
<select class="form-control select2" id="action_unit" name="action_unit">
<option>--</option>
<option value="degree">degree</option>
<option value="times">times</option>
<option value="percentage">percentage</option>
</select>
</div>
load
<div class="form-group col-md-6">
<label for="action_unit">Action Unit</label>
<select class="form-control select2" id="action_unit" name="action_unit">
<option <?php if ($action_data['ACTION_UNIT'] == 'degree') {
echo 'selected'; } ?> value=<?php echo $action_data['ACTION_UNIT'] ?>>degree</option>
<option <?php if ($action_data['ACTION_UNIT'] == 'times') {
echo 'selected';} ?> value=<?php echo $action_data['ACTION_UNIT'] ?>>times</option>
<option <?php if ($action_data['ACTION_UNIT'] == 'percentage') {
echo 'selected';} ?> value=<?php echo $action_data['ACTION_UNIT'] ?>>percentage</option>
</select>
)</div>