PHP SQLSRV下拉列表错误

时间:2017-07-26 19:08:36

标签: php dropdown sqlsrv

  

我正在尝试通过sqlsrv从SQL Query填充下拉列表   但它不起作用。我做错了什么?

<?php

$serverName1 = "kk12334";
$connectionInfo1 = array( "Database"=>"Fruits");
$conn1 = sqlsrv_connect( $serverName1, $connectionInfo1);
$sql1="SELECT [Name] as CName,[BName] as BName from Fruits";
$stmt1 = sqlsrv_query( $conn1, $sql1 );


while ($data=sqlsrv_fetch_array($stmt1, SQLSRV_FETCH_ASSOC))

{


  echo "<option value=";
    echo $data['CName'].", ".$data['BName'].;
    echo "<br />";
        echo $data['CName'].", ".$data['BName'];
    echo "</option>";

}

?>

1 个答案:

答案 0 :(得分:0)

您无法在<BR>&gt;中放置<option。标签

尝试类似:

while ($data=sqlsrv_fetch_array($stmt1, SQLSRV_FETCH_ASSOC))
{ $opt="$data[CName], $data[BName]";
   echo "<option value='$opt'>$opt</option>\n";
}

由于您希望在两个变量值之间留一个空格,因此您需要将所有内容都包含在'中,以确保将这两个部分分配到value=