Php 单击“编辑”时,如何保留“数据库驱动”下拉列表框的值?
你好 我想问一下,在编辑下拉框时,如何保留下拉框的值 以我的形式Php 单击“编辑”时,如何保留“数据库驱动”下拉列表框的值?,php,mysql,Php,Mysql,你好 我想问一下,在编辑下拉框时,如何保留下拉框的值 以我的形式 <tr> <td><strong>*Die Type:</strong></td> <td> <?php $query = "SELECT * FROM idie_type_tbl" ; $result = mysql_query($query); echo'<
<tr>
<td><strong>*Die Type:</strong></td>
<td>
<?php
$query = "SELECT * FROM idie_type_tbl" ;
$result = mysql_query($query);
echo'<select name="die_type" class="textfield">';
while($row = mysql_fetch_assoc( $result )) {
echo '<option value="'.$row['die_type_id'].'">' . $row['die_type'] . '</option>';
}
echo '</select>';
?>
</td>
*模具类型:
在我的edit.php脚本中也是如此。如何在edit.php中保留数据库驱动下拉框的值
谢谢
$\u Get/POST
属性(如果有)
正如@Quentin所说的,按照他的指示使用下面的代码
while($row = mysql_fetch_assoc( $result )) {
if($_POST['die_type'] == $row['die_type_id']) {
echo '<option value="'.$row['die_type_id'].'" selected = "selected">' . $row['die_type'] . '</option>';
} else {
echo '<option value="'.$row['die_type_id'].'">' . $row['die_type'] . '</option>';
}
}
while($row=mysql\u fetch\u assoc($result)){
如果($\u POST['die\u type']=$row['die\u type\u id'])){
回显'.$row['die_type'].';
}否则{
回显'.$row['die_type'].';
}
}
您正在使用并且应该使用。Lol您删除了您的问题…但请确保您仔细使用pdo。请参阅以下答案@ChocoMartin您在表单中使用的是哪种方法GET
或POST
?@ChocoMartin那么它应该可以工作了。你能详细说明一下仍然不正常
的意思吗?我已经更改了我的代码并使用了你的代码。还是不行。我已经使用POST作为方法。单击“编辑”时,第一个选项仍显示在dropdown@yoyesh我怎样才能从我的帖子中获得提交值的值