显示从数据库中选择的下拉值(iemysql)

时间:2017-07-10 06:23:36

标签: javascript jquery mysql

我已将选择下拉菜单中的苹果值保存到mysql中。 现在在编辑页面中,我想显示相应的值。 但我似乎没有把它弄好



<?php $food = $mysqli->real_escape_string($_POST['food']); ?>

<select id="food" required name="food" >

    <option value="" disabled selected>Select a Food</option>
    <option value="apple" <?php if($food == apple) 
    echo "selected='selected'"; ?>Apple</option>
    
    <option value="kiwi" <?php if($food == kiwi) 
    echo "selected='selected'"; ?>Kiwi</option>
</select></div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

&#13;
&#13;
<select id="food" required name="food" >

    <option value="" >Select a Food</option>
    <option value="apple" <?php if($food == "apple") 
    echo "selected='selected'"; ?>Apple</option>
    
    <option value="kiwi" <?php if($food == "kiwi") 
    echo "selected='selected'"; ?>Kiwi</option>
</select></div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

single应附加double引号或if($food == 'apple')引号<select id="food" required name="food" > <option value="" disabled selected>Select a Food</option> <option value="apple" <?php if($food == 'apple') echo "selected='selected'"; ?>Apple</option> <option value="kiwi" <?php if($food == 'kiwi') echo "selected='selected'"; ?>Kiwi</option> </select></div>

$query = Doctrine_Query::create()
  ->from('attendanceRecord a')
  ->whereIn('a.employeeId', $employeeId);