0
$sql = "select custName from customer where active = 1 order by custName";
sult=mysql_query($sql);
echo"<select name='custNameColo'>";
while($row = mysql_fetch_array($result)) {
    if($row['custName']==$_GET['defaultCust']) {
        echo "<option value=".$row['custName']."selected = 'selected'>".$row['custName']."</option>";
    }
    else {
        echo "<option value=".$row['custName'].">".$row['custName']."</option>";
    }
}
echo "</select>";

我想在下拉菜单中设置一个默认值,但它不起作用,请帮助我。

4

3 回答 3

0
<?php 
$sql = "select custName from customer where active = 1 order by custName";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result)){
?>
<option value="<?php echo $row['custname'] ?>" <?php if($row['custname']==$_GET['defaultCust']) { echo "selected";}?>>
<?php echo $row['custname']; ?></option>
<?php
}
 ?>
于 2013-01-01T10:37:12.603 回答
0
<?  echo "TRY this it will work";
$sql = "select custName from customer where active = 1 order by custName";
$result=mysql_query($sql);
?>
<select name="custNameColo">
<? 
while($row = mysql_fetch_array($result)){?>
<option value="<?=$row['custname'];?>" <? if($row['custname']==$_GET['defaultCust']){?> selected="selected" <? }?>><?=$row['custname'];?></option>
<? } ?>
</select>
于 2013-01-01T12:06:48.570 回答
-1

您没有在选项标签的值之前和之后添加单引号。我为你做了。未选择默认值,因为 value 属性未正确关闭。

$sql = "select custName from customer where active = 1 order by custName";
$result=mysql_query($sql);
echo "<select name='custNameColo'>";
while($row = mysql_fetch_array($result)){
    if($row['custName']==$_GET['defaultCust']){
        echo "<option value='".$row['custName']."' selected = 'selected'>".$row['custName']."</option>";
    }
    else {
        echo "<option value='".$row['custName']."'>".$row['custName']."</option>";
    }
}
echo "</select>";
于 2013-01-01T10:17:13.640 回答