所以我有一个基本的选择下拉框:
<select class="form-control" name="work_place">
<option>Work Place 1</option>
<option>Work Place 2</option>
<option>Work Place 3</option>
<option>Work Place 4</option>
</select>
使用php代码:
$work = $_POST['work_place'];
如果我想稍后编辑它,回显所选值的最佳方法是什么?
解决 感谢&#34; help&#34;,以下是答案:
<select class="form-control" name="work_place">
<option <?php echo ($edit_row["workPlace"] === "Work Place 1")?"selected" : ""; ?> >Work Place 1</option>
<option <?php echo ($edit_row["workPlace"] === "Work Place 2")?"selected" : ""; ?> >Work Place 2</option>
<option <?php echo ($edit_row["workPlace"] === "Work Place 3")?"selected" : ""; ?> >Work Place 3</option>
<option <?php echo ($edit_row["workPlace"] === "Work Place 4")?"selected" : ""; ?> >Work Place 4</option>
</select>
它回显了所选的下拉选项。
答案 0 :(得分:0)
尝试这个
<form action="" method="post">
<select class="form-control" name="work_place">
<option value="Work Place 1">Work Place 1</option>
<option value="Work Place 2">Work Place 2</option>
<option value="Work Place 3">Work Place 3</option>
<option value="Work Place 4">Work Place 4</option>
</select>
<input type="submit" value="go" />
</form>
<?php
$post = (isset($_POST['work_place'])) ? $_POST['work_place'] : '';
echo $post;
?>