使用php填充下拉选择的值
我有一个下拉菜单,用户可以从中选择位置。这些是保存的设置,因此如果用户想要编辑这些设置,我希望以前保存的值填充列表 位置及其ID是从名为locations的表中选择的,但是,只有该位置保存在名为userinfo的表中。考虑到第一次在选择过程中使用了id,我不确定如何再次填充选择列表 这就是我现在要做的,简单地选择一个选项。我想用以前保存的位置来填充这个。这是较大表单的一部分,因此没有表单标记使用php填充下拉选择的值,php,mysql,Php,Mysql,我有一个下拉菜单,用户可以从中选择位置。这些是保存的设置,因此如果用户想要编辑这些设置,我希望以前保存的值填充列表 位置及其ID是从名为locations的表中选择的,但是,只有该位置保存在名为userinfo的表中。考虑到第一次在选择过程中使用了id,我不确定如何再次填充选择列表 这就是我现在要做的,简单地选择一个选项。我想用以前保存的位置来填充这个。这是较大表单的一部分,因此没有表单标记 <? $sql = mysql_query("select locationsid,locatio
<?
$sql = mysql_query("select locationsid,locationsName from locations");
$selection="";
while ($row=mysql_fetch_array($sql)){
$id=$row["locationsid"];
$locationName = $row["locationsName"];
$selection.="<OPTION VALUE=\"$id\">".$locationName;
}
?>
<!--select location - used for reach location -->
<h4>Nearest Location</h4>
<table>
<tr><td>Location:</td><td><select name ="location"><Option value="<? echo selection2; ?>">Choose Location<? echo $selection; ?></Select></td>
</table>
因此,这将给我名称和ID,我如何将其设置为选择列表中的值?在您获得
$idlookup
后:
$idlookup = $locationid['locationsID'];
在内使用它,而循环:
while ($row=mysql_fetch_array($sql)){
$id=$row["locationsid"];
$locationName = $row["locationsName"];
$selected = ($id == $idlookup) ? 'selected="selected"' : '';
$selection.="<OPTION " . $selected . " VALUE=\"$id\">".$locationName."</OPTION>";
}
while($row=mysql\u fetch\u array($sql)){
$id=$row[“locationsid”];
$locationName=$row[“locationsName”];
$selected=($id==$idlookup)?'selected=“selected”:'';
$selection.=''.$locationName.'';
}
获得$idlookup
后:
$idlookup = $locationid['locationsID'];
在内使用它,而循环:
while ($row=mysql_fetch_array($sql)){
$id=$row["locationsid"];
$locationName = $row["locationsName"];
$selected = ($id == $idlookup) ? 'selected="selected"' : '';
$selection.="<OPTION " . $selected . " VALUE=\"$id\">".$locationName."</OPTION>";
}
while($row=mysql\u fetch\u array($sql)){
$id=$row[“locationsid”];
$locationName=$row[“locationsName”];
$selected=($id==$idlookup)?'selected=“selected”:'';
$selection.=''.$locationName.'';
}
您不关闭选项
块您不关闭选项
块