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 に答える